{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}/Users/connorforsythe/Library/CloudStorage/Box-Box/CMU/Marginal Mileage Project/Publication Replication Code/JAERE/PrimaryModel/ReviewResponseResults/ReviewResponse.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res} 2 Sep 2025, 21:46:56
{com}.         local tableSaveDir = "ReviewResponseResults/"
.         local plotSaveDir = "ReviewResponseResults/"
.         local pythonSaveDir = "PythonScripts/"
. {c )-}
{txt}
{com}. 
. 
. //Start Timer
. timer on 1
{txt}
{com}. 
. //Load useful programs
. do programs
{txt}
{com}. 
. //Adds the first robust first stage f-stat as described in Andrews, Stock, and Sun (2019) p.737; stores result in "fStat"
. program addRobustFStat
{txt}  1{com}.         version 16.1
{txt}  2{com}.         args varToAdd
{txt}  3{com}.         estadd scalar fStat = (_b[`varToAdd']^2)/e(V)["`varToAdd'", "`varToAdd'"]
{txt}  4{com}.         
.         
. end
{txt}
{com}. 
. //Adds the first treatment coefficient and standard error; stores result in "treatb" and "treatse"
. program addTreat
{txt}  1{com}.         version 16.1
{txt}  2{com}.         args varToAdd
{txt}  3{com}.         qui estadd local treatse = "(0"+string(round(_se[`varToAdd'], .001))+")"
{txt}  4{com}.         
.         
.         local tempb = string(round(_b[`varToAdd'], .001))
{txt}  5{com}.         
.         di "hello"
{txt}  6{com}.         
.         local colonIndex = ustrrpos("`varToAdd'", ":")
{txt}  7{com}.         local strLen = strlen("`varToAdd'")
{txt}  8{com}.         local eqno = udsubstr("`varToAdd'",1,`colonIndex'-1)
{txt}  9{com}.         local varName = udsubstr("`varToAdd'",`colonIndex'+1,`strLen'+`colonIndex'-1)
{txt} 10{com}.         di "`colonIndex'"
{txt} 11{com}.         di "`eqno'"
{txt} 12{com}.         di "`varName'"
{txt} 13{com}.         
.         test [`eqno']`varName'
{txt} 14{com}.         di "hello2"
{txt} 15{com}.         
.         
.         //Determine Stars for alternate null
.         local stars = ""
{txt} 16{com}.                         
.         if(`r(p)'<0.01){c -(}
{txt} 17{com}.                 local stars = "***"
{txt} 18{com}.         {c )-}       
{txt} 19{com}.         else if(`r(p)'<0.05){c -(}
{txt} 20{com}.                 local stars = "**"
{txt} 21{com}.         {c )-}
{txt} 22{com}.         else if(`r(p)'<0.1){c -(}
{txt} 23{com}.                 local stars = "*"
{txt} 24{com}.         {c )-}
{txt} 25{com}. 
.         estadd local treatb = "0`tempb'"+"`stars'"
{txt} 26{com}.         
.         
. end
{txt}
{com}. 
. //Program to test some specified null; 
. program testNull, rclass
{txt}  1{com}.         version 16.1
{txt}  2{com}.         args pi delta piVar deltaVar covar null
{txt}  3{com}.         
.         tempname arStat pVal
{txt}  4{com}.         
.         scalar `arStat' = ((`delta'-`pi'*`null')^2)/(`deltaVar'+(`null')^2*`piVar'-2*`null'*`covar')
{txt}  5{com}.         scalar `pVal' = 1-chi2(1, `arStat')
{txt}  6{com}.         
.         
.         return scalar pi = `pi'
{txt}  7{com}.         return scalar delta = `delta'
{txt}  8{com}.         return scalar piVar = `piVar'
{txt}  9{com}.         return scalar deltaVar = `deltaVar'
{txt} 10{com}.         return scalar covar = `covar'
{txt} 11{com}.         return scalar arStat = `arStat'
{txt} 12{com}.         return scalar pVal = `pVal'
{txt} 13{com}.         return scalar null = `null'
{txt} 14{com}.         return scalar beta = `delta'/`pi'
{txt} 15{com}. 
. end
{txt}
{com}. 
. //Program to jointly estimate first stage and reduced form; argument structure is first-stage model, reduced form model, cluster variable, treatmentVar, and the model title
. program jointEstimate, rclass
{txt}  1{com}.         version 16.1 //Establish Version
{txt}  2{com}.         //Parse arguments
.         gettoken fsVars 0:0, parse(",")
{txt}  3{com}.         gettoken com 0:0, parse(",")
{txt}  4{com}.         gettoken rfVars 0:0, parse(",")
{txt}  5{com}.         gettoken com 0:0, parse(",")
{txt}  6{com}.         gettoken clusterVar 0:0, parse(",")
{txt}  7{com}.         gettoken com 0:0, parse(",")
{txt}  8{com}.         gettoken treatmentVar 0:0, parse(",")
{txt}  9{com}.         gettoken com 0:0, parse(",")
{txt} 10{com}.         gettoken modelTitle 0:0, parse(",")
{txt} 11{com}. 
.         di "Working on:`modelTitle'"
{txt} 12{com}.         
.         
.         
.         //Establish Temporary Variables
.         tempname fsK rfK N nClust fsCorrection rfCorrection pi delta piVarUncorrected deltaVarUncorrected covarUncorrected piVar deltaVar covar covarHigh covarLow
{txt} 13{com}.         
.         regress `fsVars'
{txt} 14{com}.         scalar `fsK' = e(df_m)+1
{txt} 15{com}.         return scalar fsK = `fsK'
{txt} 16{com}.         estimates store fs 
{txt} 17{com}.                 
.         regress `rfVars'
{txt} 18{com}.         scalar `rfK' = e(df_m)+1
{txt} 19{com}.         return scalar rfK = `rfK'
{txt} 20{com}.         estimates store rf 
{txt} 21{com}.         
.         qui suest fs rf, vce(cluster `clusterVar')
{txt} 22{com}.         scalar `nClust' = e(N_clust)
{txt} 23{com}.         scalar `N' = e(N)
{txt} 24{com}.         scalar `pi' = e(b)["y1", "fs_mean:`treatmentVar'"]
{txt} 25{com}.         scalar `delta' = e(b)["y1", "rf_mean:`treatmentVar'"]
{txt} 26{com}.         scalar `piVarUncorrected' = e(V)["fs_mean:`treatmentVar'", "fs_mean:`treatmentVar'"]
{txt} 27{com}.         scalar `deltaVarUncorrected' = e(V)["rf_mean:`treatmentVar'", "rf_mean:`treatmentVar'"]
{txt} 28{com}.         scalar `covarUncorrected' = e(V)["rf_mean:`treatmentVar'", "fs_mean:`treatmentVar'"]
{txt} 29{com}.         
.         
.         return scalar nClust = `nClust'
{txt} 30{com}.         return scalar N = `N'
{txt} 31{com}.         scalar `fsCorrection' = (`N'-1)/(`N'-`fsK'+(`nClust'-1))
{txt} 32{com}.         scalar `rfCorrection' = (`N'-1)/(`N'-`rfK'+(`nClust'-1))
{txt} 33{com}.         scalar `piVar' = `piVarUncorrected'*`fsCorrection'
{txt} 34{com}.         scalar `deltaVar' = `deltaVarUncorrected'*`fsCorrection'
{txt} 35{com}.         scalar `covarHigh' = max(`fsCorrection'*`covarUncorrected',`rfCorrection'*`covarUncorrected')
{txt} 36{com}.         scalar `covarLow' = min(`fsCorrection'*`covarUncorrected',`rfCorrection'*`covarUncorrected')
{txt} 37{com}.         scalar `covar' = `covarLow'
{txt} 38{com}.         
.         return scalar fsCorrection = `fsCorrection'
{txt} 39{com}.         return scalar rfCorrection = `rfCorrection'
{txt} 40{com}.         return scalar pi = `pi'
{txt} 41{com}.         return scalar delta = `delta'
{txt} 42{com}.         return scalar piVarUncorrected = `piVarUncorrected'
{txt} 43{com}.         return scalar deltaVarUncorrected = `deltaVarUncorrected'
{txt} 44{com}.         return scalar covarUncorrected = `covarUncorrected'
{txt} 45{com}.         return scalar piVar = `piVar'
{txt} 46{com}.         return scalar deltaVar = `deltaVar'
{txt} 47{com}.         return scalar covarHigh = `covarHigh'
{txt} 48{com}.         return scalar covarLow = `covarLow'
{txt} 49{com}.         return scalar covar = `covar'
{txt} 50{com}.         
.         
. end
{txt}
{com}. 
. program regFWL, eclass
{txt}  1{com}.         version 16.1 //Establish Version
{txt}  2{com}.         
.         gettoken out_var 0:0, parse(",")
{txt}  3{com}.         gettoken com 0:0, parse(",")
{txt}  4{com}.         gettoken est_var 0:0, parse(",")
{txt}  5{com}.         gettoken com 0:0, parse(",")
{txt}  6{com}.         gettoken partial_var 0:0, parse(",")
{txt}  7{com}.         gettoken com 0:0, parse(",")
{txt}  8{com}.         gettoken absorb_vars 0:0, parse(",")
{txt}  9{com}.         gettoken com 0:0, parse(",")
{txt} 10{com}.         gettoken cluster_var 0:0, parse(",")
{txt} 11{com}.         gettoken com 0:0, parse(",")
{txt} 12{com}.         gettoken res_var 0:0, parse(",")
{txt} 13{com}.         gettoken com 0:0, parse(",")
{txt} 14{com}.         
.         
.         if("`out_var'"=="_") local out_var = ""
{txt} 15{com}.         if("`est_var'"=="_") local est_var = ""
{txt} 16{com}.         if("`partial_var'"=="_") local partial_var = ""
{txt} 17{com}.         if("`absorb_vars'"=="_") local absorb_vars = ""
{txt} 18{com}.         if("`cluster_var'"=="_") local cluster_var = ""
{txt} 19{com}.         if("`res_var'"=="_") local res_var = ""
{txt} 20{com}.         
.         local numClusterVar = 0
{txt} 21{com}.         
.         foreach tempVar in `cluster_var'{c -(}
{txt} 22{com}.                 local numClusterVar = `numClusterVar'+1
{txt} 23{com}.                 local clusterVar`numClusterVar' = "`tempVar'"
{txt} 24{com}.         {c )-}
{txt} 25{com}.         di "absorb: `absorb_vars'"
{txt} 26{com}.         qui reghdfe `out_var' `partial_var', absorb(`absorb_vars') res(`out_var'_res)
{txt} 27{com}.         local new_dep = "`out_var'_res"
{txt} 28{com}.         local new_ind = ""
{txt} 29{com}.         
.         local num_est = 0
{txt} 30{com}.         if("`est_var'"!=""){c -(}
{txt} 31{com}.                 foreach temp_var in `est_var'{c -(}
{txt} 32{com}.                         qui reghdfe `temp_var' `partial_var', absorb(`absorb_vars') res(`temp_var'_res)
{txt} 33{com}.                         local new_ind = "`new_ind' `temp_var'_res"
{txt} 34{com}.                         local num_est = `num_est'+1
{txt} 35{com}.                 {c )-}
{txt} 36{com}.         {c )-}
{txt} 37{com}.         
.         //Run just to get correct values for k; this is the full regression, so other statistics that are unrelated to covariance can be used
.         if("`res_var'"==""){c -(}
{txt} 38{com}.                 qui reghdfe `out_var' `est_var' `partial_var', absorb(`absorb_vars') cluster(`cluster_var')
{txt} 39{com}.         {c )-}
{txt} 40{com}.         else{c -(}
{txt} 41{com}.                 qui reghdfe `out_var' `est_var' `partial_var', absorb(`absorb_vars') cluster(`cluster_var') res(`res_var')
{txt} 42{com}.         {c )-}
{txt} 43{com}.         local k = e(df_a)+e(df_m)
{txt} 44{com}.         local N = e(N)
{txt} 45{com}.         local r2 = e(r2)
{txt} 46{com}.         qui reghdfe `new_dep' `new_ind', noabsorb nocon cluster(`cluster_var')
{txt} 47{com}.         
.         qui regress `new_dep' `new_ind', nocon
{txt} 48{com}.         ereturn list
{txt} 49{com}.         
.         estimates store mod1
{txt} 50{com}.         
.         qui suest mod1, vce(cluster `clusterVar1')
{txt} 51{com}.         local nClust1 = e(N_clust)
{txt} 52{com}.         mat var1 = e(V)
{txt} 53{com}.         
.         qui suest mod1, vce(cluster `clusterVar2')
{txt} 54{com}.         local nClust2 = e(N_clust)
{txt} 55{com}.         mat var2 = e(V)
{txt} 56{com}.         
.         qui suest mod1, vce(robust)
{txt} 57{com}.         
.         mat varR = e(V)
{txt} 58{com}.         mat beta = e(b)
{txt} 59{com}.         
.         
.         mat mat_var = var1+var2-varR
{txt} 60{com}.         local nClust = min(`nClust1', `nClust2')
{txt} 61{com}.         local correction = (`nClust')/(`nClust'-1)*(`N'-1)/(`N'-`k')
{txt} 62{com}.         mat mat_var = `correction'*mat_var
{txt} 63{com}.         matlist mat_var
{txt} 64{com}.         ereturn post beta mat_var
{txt} 65{com}.         ereturn scalar r2 = `r2'
{txt} 66{com}.         ereturn scalar N = `N'
{txt} 67{com}.         ereturn scalar N_clust = `nClust'
{txt} 68{com}.         drop `new_dep' `new_ind'
{txt} 69{com}. 
.         //Complete
. end
{txt}
{com}. 
. 
. 
. program jointEstimateFWL, rclass
{txt}  1{com}.         version 16.1 //Establish Version
{txt}  2{com}.         //Parse arguments
.         gettoken fsOut 0:0, parse(",")
{txt}  3{com}.         gettoken com 0:0, parse(",")
{txt}  4{com}.         gettoken rfOut 0:0, parse(",")
{txt}  5{com}.         gettoken com 0:0, parse(",")
{txt}  6{com}.         gettoken fsControls 0:0, parse(",")
{txt}  7{com}.         gettoken com 0:0, parse(",")
{txt}  8{com}.         gettoken rfControls 0:0, parse(",")
{txt}  9{com}.         gettoken com 0:0, parse(",")
{txt} 10{com}.         gettoken treatControl 0:0, parse(",")
{txt} 11{com}.         gettoken com 0:0, parse(",")
{txt} 12{com}.         gettoken absorbVars 0:0, parse(",")
{txt} 13{com}.         gettoken com 0:0, parse(",")
{txt} 14{com}.         gettoken clusterVar 0:0, parse(",")
{txt} 15{com}.         gettoken com 0:0, parse(",")
{txt} 16{com}.         gettoken treatmentVar 0:0, parse(",")
{txt} 17{com}.         gettoken com 0:0, parse(",")
{txt} 18{com}.         gettoken modelTitle 0:0, parse(",")
{txt} 19{com}. 
.         di "Working on:`modelTitle'"
{txt} 20{com}.         
.         local numClusterVar = 0
{txt} 21{com}.         
.         foreach tempVar in `clusterVar'{c -(}
{txt} 22{com}.                 local numClusterVar = `numClusterVar'+1
{txt} 23{com}.                 local clusterVar`numClusterVar' = "`tempVar'"
{txt} 24{com}.         {c )-}
{txt} 25{com}.         
.         //Establish Temporary Variables
.         tempname fsK rfK N nClust nClust1 nClust2 fsCorrection rfCorrection pi delta piVarUncorrected deltaVarUncorrected covarUncorrected piVar deltaVar covar covarHigh covarLow piVarUncorrected1 deltaVarUncorrected1 covarUncorrected1 piVarUncorrected2 deltaVarUncorrected2 covarUncorrected2 piVarUncorrectedR deltaVarUncorrectedR covarUncorrectedR 
{txt} 26{com}.         
.         qui reghdfe `fsOut' `fsControls', absorb(`absorbVars') res(`fsOut'_res) cluster(`clusterVar')
{txt} 27{com}.         scalar `fsK' = e(df_a)+e(df_m)+1 //Adding 1 because second regression only has one regressor by construction, so this accounts for all regressors
{txt} 28{com}.         
.         qui reghdfe `treatControl' `fsControls', absorb(`absorbVars') res(fs_`treatControl'_res)
{txt} 29{com}.         
.         regress `fsOut'_res fs_`treatControl'_res, nocon
{txt} 30{com}.         
.         return scalar fsK = `fsK'
{txt} 31{com}.         estimates store fs 
{txt} 32{com}.                 
.         qui reghdfe `rfOut' `rfControls', absorb(`absorbVars') res(`rfOut'_res) cluster(`clusterVar')
{txt} 33{com}.         scalar `rfK' = e(df_a)+e(df_m)+1 //Adding 1 because second regression only has one regressor by construction, so this accounts for all regressors
{txt} 34{com}.         
.         qui reghdfe `treatControl' `rfControls', absorb(`absorbVars') res(rf_`treatControl'_res)
{txt} 35{com}.         
.         qui regress `rfOut'_res rf_`treatControl'_res, nocon
{txt} 36{com}.         
.         
.         return scalar rfK = `rfK'
{txt} 37{com}.         estimates store rf 
{txt} 38{com}.         
.         if `numClusterVar'==1{c -(}
{txt} 39{com}.                 qui suest fs rf, vce(cluster `clusterVar')
{txt} 40{com}.         
.                 scalar `nClust' = e(N_clust)
{txt} 41{com}.                 scalar `N' = e(N)
{txt} 42{com}.                 scalar `pi' = e(b)["y1", "fs_mean:fs_`treatControl'_res"]
{txt} 43{com}.                 scalar `delta' = e(b)["y1", "rf_mean:rf_`treatControl'_res"]
{txt} 44{com}.                 scalar `piVarUncorrected' = e(V)["fs_mean:fs_`treatControl'_res", "fs_mean:fs_`treatControl'_res"]
{txt} 45{com}.                 scalar `deltaVarUncorrected' = e(V)["rf_mean:rf_`treatControl'_res", "rf_mean:rf_`treatControl'_res"]
{txt} 46{com}.                 scalar `covarUncorrected' = e(V)["rf_mean:rf_`treatControl'_res", "fs_mean:fs_`treatControl'_res"]
{txt} 47{com}.         {c )-}
{txt} 48{com}.         else{c -(}
{txt} 49{com}.                 di "Current approach can handle two-way clustering. Higher dimensional clustering will produce incorrect results."
{txt} 50{com}.                 qui suest fs rf, vce(cluster `clusterVar1')
{txt} 51{com}.                 scalar `nClust1' = e(N_clust)
{txt} 52{com}.                 scalar `N' = e(N)
{txt} 53{com}.                 scalar `pi' = e(b)["y1", "fs_mean:fs_`treatControl'_res"]
{txt} 54{com}.                 scalar `delta' = e(b)["y1", "rf_mean:rf_`treatControl'_res"]
{txt} 55{com}.                 scalar `piVarUncorrected1' = e(V)["fs_mean:fs_`treatControl'_res", "fs_mean:fs_`treatControl'_res"]
{txt} 56{com}.                 scalar `deltaVarUncorrected1' = e(V)["rf_mean:rf_`treatControl'_res", "rf_mean:rf_`treatControl'_res"]
{txt} 57{com}.                 scalar `covarUncorrected1' = e(V)["rf_mean:rf_`treatControl'_res", "fs_mean:fs_`treatControl'_res"]
{txt} 58{com}.                 
.                 return scalar piVarUncorrected1 = `piVarUncorrected1'
{txt} 59{com}.                 return scalar deltaVarUncorrected1 = `deltaVarUncorrected1'
{txt} 60{com}.                 return scalar covarUncorrected1 = `covarUncorrected1'
{txt} 61{com}.                 
.                 qui suest fs rf, vce(cluster `clusterVar2')
{txt} 62{com}.                 
.                 scalar `nClust2' = e(N_clust)
{txt} 63{com}.                 scalar `piVarUncorrected2' = e(V)["fs_mean:fs_`treatControl'_res", "fs_mean:fs_`treatControl'_res"]
{txt} 64{com}.                 scalar `deltaVarUncorrected2' = e(V)["rf_mean:rf_`treatControl'_res", "rf_mean:rf_`treatControl'_res"]
{txt} 65{com}.                 scalar `covarUncorrected2' = e(V)["rf_mean:rf_`treatControl'_res", "fs_mean:fs_`treatControl'_res"]
{txt} 66{com}.                 
.                 return scalar piVarUncorrected2 = `piVarUncorrected2'
{txt} 67{com}.                 return scalar deltaVarUncorrected2 = `deltaVarUncorrected2'
{txt} 68{com}.                 return scalar covarUncorrected2 = `covarUncorrected2'
{txt} 69{com}.                 
.                 qui suest fs rf, vce(robust)
{txt} 70{com}.                 
.                 scalar `piVarUncorrectedR' = e(V)["fs_mean:fs_`treatControl'_res", "fs_mean:fs_`treatControl'_res"]
{txt} 71{com}.                 scalar `deltaVarUncorrectedR' = e(V)["rf_mean:rf_`treatControl'_res", "rf_mean:rf_`treatControl'_res"]
{txt} 72{com}.                 scalar `covarUncorrectedR' = e(V)["rf_mean:rf_`treatControl'_res", "fs_mean:fs_`treatControl'_res"]
{txt} 73{com}.                 
.                 return scalar piVarUncorrectedR = `piVarUncorrectedR'
{txt} 74{com}.                 return scalar deltaVarUncorrectedR = `deltaVarUncorrectedR'
{txt} 75{com}.                 return scalar covarUncorrectedR = `covarUncorrectedR'
{txt} 76{com}.                 
.                 scalar `nClust' = min(`nClust1', `nClust2')
{txt} 77{com}.                 return scalar nClust1 = `nClust1'
{txt} 78{com}.                 return scalar nClust2 = `nClust2'
{txt} 79{com}.                 scalar `piVarUncorrected' = `piVarUncorrected1'+`piVarUncorrected2'-`piVarUncorrectedR'
{txt} 80{com}.                 scalar `deltaVarUncorrected' = `deltaVarUncorrected1'+`deltaVarUncorrected2'-`deltaVarUncorrectedR'
{txt} 81{com}.                 scalar `covarUncorrected' = `covarUncorrected1'+`covarUncorrected2'-`covarUncorrectedR'
{txt} 82{com}.         {c )-}
{txt} 83{com}.         
.         
.         
.         return scalar nClust = `nClust'
{txt} 84{com}.         return scalar N = `N'
{txt} 85{com}.         scalar `fsCorrection' = (`nClust')/(`nClust'-1)*(`N'-1)/(`N'-`fsK')
{txt} 86{com}.         scalar `rfCorrection' = (`nClust')/(`nClust'-1)*(`N'-1)/(`N'-`rfK')
{txt} 87{com}.         scalar `piVar' = `piVarUncorrected'*`fsCorrection'
{txt} 88{com}.         scalar `deltaVar' = `deltaVarUncorrected'*`fsCorrection'
{txt} 89{com}.         scalar `covarHigh' = max(`fsCorrection'*`covarUncorrected',`rfCorrection'*`covarUncorrected')
{txt} 90{com}.         scalar `covarLow' = min(`fsCorrection'*`covarUncorrected',`rfCorrection'*`covarUncorrected')
{txt} 91{com}.         scalar `covar' = `covarLow'
{txt} 92{com}.         
.         return scalar fsCorrection = `fsCorrection'
{txt} 93{com}.         return scalar rfCorrection = `rfCorrection'
{txt} 94{com}.         return scalar pi = `pi'
{txt} 95{com}.         return scalar delta = `delta'
{txt} 96{com}.         return scalar piVarUncorrected = `piVarUncorrected'
{txt} 97{com}.         return scalar deltaVarUncorrected = `deltaVarUncorrected'
{txt} 98{com}.         return scalar covarUncorrected = `covarUncorrected'
{txt} 99{com}.         return scalar piVar = `piVar'
{txt}100{com}.         return scalar deltaVar = `deltaVar'
{txt}101{com}.         return scalar covarHigh = `covarHigh'
{txt}102{com}.         return scalar covarLow = `covarLow'
{txt}103{com}.         return scalar covar = `covar'
{txt}104{com}.         
.         drop `fsOut'_res fs_`treatControl'_res `rfOut'_res rf_`treatControl'_res
{txt}105{com}.         
. end
{txt}
{com}. 
. 
. //Program to output jointly estimated resuls along with a range of null hypotheses; argument structure is first-stage model, reduced form model, cluster variable, treatmentVar, modelTitle, nullLow, nullDelta, nullHigh, primary null
. program runModel
{txt}  1{com}.         version 16.1
{txt}  2{com}.         gettoken fsVars 0:0, parse(",")
{txt}  3{com}.         gettoken com 0:0, parse(",")
{txt}  4{com}.         gettoken rfVars 0:0, parse(",")
{txt}  5{com}.         gettoken com 0:0, parse(",")
{txt}  6{com}.         gettoken clusterVar 0:0, parse(",")
{txt}  7{com}.         gettoken com 0:0, parse(",")
{txt}  8{com}.         gettoken treatmentVar 0:0, parse(",")
{txt}  9{com}.         gettoken com 0:0, parse(",")
{txt} 10{com}.         gettoken modelTitle 0:0, parse(",")
{txt} 11{com}.         gettoken com 0:0, parse(",")
{txt} 12{com}.         gettoken nullLow 0:0, parse(",")
{txt} 13{com}.         gettoken com 0:0, parse(",")
{txt} 14{com}.         gettoken nullDelta 0:0, parse(",")
{txt} 15{com}.         gettoken com 0:0, parse(",")
{txt} 16{com}.         gettoken nullHigh 0:0, parse(",")
{txt} 17{com}.         gettoken com 0:0, parse(",")
{txt} 18{com}.         gettoken primaryNull 0:0, parse(",")
{txt} 19{com}.         gettoken com 0:0, parse(",")
{txt} 20{com}.         gettoken altNull 0:0, parse(",")
{txt} 21{com}.         gettoken com 0:0, parse(",")
{txt} 22{com}.         gettoken altNull2 0:0, parse(",")
{txt} 23{com}.         gettoken com 0:0, parse(",")
{txt} 24{com}.         gettoken altNull3 0:0, parse(",")
{txt} 25{com}.         gettoken com 0:0, parse(",")
{txt} 26{com}.         gettoken altNull4 0:0, parse(",")
{txt} 27{com}.         
.         tempname null tempPi tempDelta tempPiVar tempDeltaVar tempCovar fileName
{txt} 28{com}.         
.         
.         if("`c(os)'"=="Windows"){c -(}
{txt} 29{com}.                 local tableSaveDir = "Tables\"
{txt} 30{com}.                 local plotSaveDir = "Plots\"
{txt} 31{com}.                 local pythonSaveDir = "PythonScripts\"
{txt} 32{com}.         {c )-}
{txt} 33{com}.         else{c -(}
{txt} 34{com}.                 local tableSaveDir = "Tables/"
{txt} 35{com}.                 local plotSaveDir = "Plots/"
{txt} 36{com}.                 local pythonSaveDir = "PythonScripts/"
{txt} 37{com}.         {c )-}
{txt} 38{com}.         
.         local fileName = "`tableSaveDir'iv-"+"`modelTitle'"+".xlsx"
{txt} 39{com}.         
.         jointEstimate `fsVars', `rfVars', `clusterVar', `treatmentVar', `modelTitle'
{txt} 40{com}.         return list
{txt} 41{com}.         
.         scalar `tempPi' = `r(pi)'
{txt} 42{com}.         scalar `tempDelta' = `r(delta)'
{txt} 43{com}.         scalar `tempPiVar' = `r(piVar)'
{txt} 44{com}.         scalar `tempDeltaVar' = `r(deltaVar)'
{txt} 45{com}.         scalar `tempCovar' = `r(covar)'
{txt} 46{com}.         
.         python script "`pythonSaveDir'calculateARStat.py", args(`tempPi' `tempDelta' `tempPiVar' `tempDeltaVar' `tempCovar' `nullLow' `nullDelta' `nullHigh' `modelTitle')
{txt} 47{com}.         
.         putexcel set "`fileName'", sheet("JointResults") modify
{txt} 48{com}.         
.         local primaryNullString = string(`primaryNull', "%2.1f")
{txt} 49{com}.         local altNullString = string(`altNull', "%2.1f")
{txt} 50{com}.         
.         qui putexcel B1 = `r(pi)'
{txt} 51{com}.         qui putexcel B2 = `r(delta)'
{txt} 52{com}.         qui putexcel B3 = `r(piVar)'
{txt} 53{com}.         qui putexcel B4 = `r(deltaVar)'
{txt} 54{com}.         qui putexcel B5 = `r(covar)'
{txt} 55{com}.         qui putexcel B6 = `r(covarHigh)'
{txt} 56{com}.         qui putexcel B7 = `r(covarLow)'
{txt} 57{com}.         qui putexcel B8 = `r(piVarUncorrected)'
{txt} 58{com}.         qui putexcel B9 = `r(deltaVarUncorrected)'
{txt} 59{com}.         qui putexcel B10 = `r(covarUncorrected)'
{txt} 60{com}.         qui putexcel B11 = `r(fsCorrection)'
{txt} 61{com}.         qui putexcel B12 = `r(rfCorrection)'
{txt} 62{com}.         qui putexcel B13 = `r(N)'
{txt} 63{com}.         qui putexcel B14 = `r(nClust)'
{txt} 64{com}.         qui putexcel B15 = `r(fsK)'
{txt} 65{com}.         qui putexcel B16 = `r(rfK)'
{txt} 66{com}.         
.         qui putexcel A1 = "pi"
{txt} 67{com}.         qui putexcel A2 = "delta"
{txt} 68{com}.         qui putexcel A3 = "pi variance"
{txt} 69{com}.         qui putexcel A4 = "delta variance"
{txt} 70{com}.         qui putexcel A5 = "pi-delta covariance"
{txt} 71{com}.         qui putexcel A6 = "pi-delta covariance high"
{txt} 72{com}.         qui putexcel A7 = "pi-delta covariance low"
{txt} 73{com}.         qui putexcel A8 = "pi variance uncorrected"
{txt} 74{com}.         qui putexcel A9 = "delta variance uncorrected"
{txt} 75{com}.         qui putexcel A10 = "pi-delta covariance uncorrected"
{txt} 76{com}.         qui putexcel A11 = "first stage finite-sample correction"
{txt} 77{com}.         qui putexcel A12 = "reduced form finite-sample correction"
{txt} 78{com}.         qui putexcel A13 = "N"
{txt} 79{com}.         qui putexcel A14 = "N Clusters"
{txt} 80{com}.         qui putexcel A15 = "first stage k"
{txt} 81{com}.         qui putexcel A16 = "reduced form k"
{txt} 82{com}.         qui putexcel A17 = "AR(Beta=`primaryNullString')"
{txt} 83{com}.         qui putexcel A18 = "P-Value(Beta=`primaryNullString')"
{txt} 84{com}.         qui putexcel A19 = "beta"
{txt} 85{com}.         qui putexcel A20 = "AR(Beta=`altNullString')"
{txt} 86{com}.         qui putexcel A21 = "P-Value(Beta=`altNullString')"
{txt} 87{com}.         qui putexcel A22 = "AR(Beta=`altNull2')"
{txt} 88{com}.         qui putexcel A23 = "P-Value(Beta=`altNull2')"
{txt} 89{com}.         qui putexcel A24 = "AR(Beta=`altNull3')"
{txt} 90{com}.         qui putexcel A25 = "P-Value(Beta=`altNull3')"
{txt} 91{com}.         qui putexcel A26 = "AR(Beta=`altNull4')"
{txt} 92{com}.         qui putexcel A27 = "P-Value(Beta=`altNull4')"
{txt} 93{com}.         
.         
.         
.         testNull `tempPi' `tempDelta' `tempPiVar' `tempDeltaVar' `tempCovar' `primaryNull'
{txt} 94{com}.         
.         qui putexcel B17 = `r(arStat)'
{txt} 95{com}.         qui putexcel B18 = `r(pVal)'
{txt} 96{com}.         qui putexcel B19 = `r(beta)'
{txt} 97{com}.         
.         testNull `tempPi' `tempDelta' `tempPiVar' `tempDeltaVar' `tempCovar' `altNull'
{txt} 98{com}.         qui putexcel B20 = `r(arStat)'
{txt} 99{com}.         qui putexcel B21 = `r(pVal)'
{txt}100{com}.         
.         testNull `tempPi' `tempDelta' `tempPiVar' `tempDeltaVar' `tempCovar' `altNull2'
{txt}101{com}.         qui putexcel B22 = `r(arStat)'
{txt}102{com}.         qui putexcel B23 = `r(pVal)'
{txt}103{com}.         
.         if("`altNull2'"!="`altNull3'"){c -(}
{txt}104{com}.                 qui putexcel A24 = "AR(Beta=`altNull3')"
{txt}105{com}.                 qui putexcel A25 = "P-Value(Beta=`altNull3')"
{txt}106{com}.                 
.                 testNull `tempPi' `tempDelta' `tempPiVar' `tempDeltaVar' `tempCovar' `altNull3'
{txt}107{com}.                 qui putexcel B24 = `r(arStat)'
{txt}108{com}.                 qui putexcel B25 = `r(pVal)'
{txt}109{com}.         {c )-}
{txt}110{com}.         if("`altNull3'"!="`altNull4'"){c -(}
{txt}111{com}.                 qui putexcel A26 = "AR(Beta=`altNull4')"
{txt}112{com}.                 qui putexcel A27 = "P-Value(Beta=`altNull4')"
{txt}113{com}.                 
.                 testNull `tempPi' `tempDelta' `tempPiVar' `tempDeltaVar' `tempCovar' `altNull4'
{txt}114{com}.                 qui putexcel B26 = `r(arStat)'
{txt}115{com}.                 qui putexcel B27 = `r(pVal)'
{txt}116{com}.         {c )-}
{txt}117{com}.         
. 
. end
{txt}
{com}. 
. //Program to output jointly estimated resuls along with a range of null hypotheses; argument structure is first-stage model, reduced form model, cluster variable, treatmentVar, modelTitle, nullLow, nullDelta, nullHigh, primary null
. program runModelFWL
{txt}  1{com}.         version 16.1
{txt}  2{com}.         gettoken fsOut 0:0, parse(",")
{txt}  3{com}.         gettoken com 0:0, parse(",")
{txt}  4{com}.         gettoken rfOut 0:0, parse(",")
{txt}  5{com}.         gettoken com 0:0, parse(",")
{txt}  6{com}.         gettoken fsControls 0:0, parse(",")
{txt}  7{com}.         gettoken com 0:0, parse(",")
{txt}  8{com}.         gettoken rfControls 0:0, parse(",")
{txt}  9{com}.         gettoken com 0:0, parse(",")
{txt} 10{com}.         gettoken treatControl 0:0, parse(",")
{txt} 11{com}.         gettoken com 0:0, parse(",")
{txt} 12{com}.         gettoken absorbVars 0:0, parse(",")
{txt} 13{com}.         gettoken com 0:0, parse(",")
{txt} 14{com}.         gettoken clusterVar 0:0, parse(",")
{txt} 15{com}.         gettoken com 0:0, parse(",")
{txt} 16{com}.         gettoken treatmentVar 0:0, parse(",")
{txt} 17{com}.         gettoken com 0:0, parse(",")
{txt} 18{com}.         gettoken modelTitle 0:0, parse(",")
{txt} 19{com}.         gettoken com 0:0, parse(",")
{txt} 20{com}.         gettoken nullLow 0:0, parse(",")
{txt} 21{com}.         gettoken com 0:0, parse(",")
{txt} 22{com}.         gettoken nullDelta 0:0, parse(",")
{txt} 23{com}.         gettoken com 0:0, parse(",")
{txt} 24{com}.         gettoken nullHigh 0:0, parse(",")
{txt} 25{com}.         gettoken com 0:0, parse(",")
{txt} 26{com}.         gettoken primaryNull 0:0, parse(",")
{txt} 27{com}.         gettoken com 0:0, parse(",")
{txt} 28{com}.         gettoken altNull 0:0, parse(",")
{txt} 29{com}.         gettoken com 0:0, parse(",")
{txt} 30{com}.         gettoken altNull2 0:0, parse(",")
{txt} 31{com}.         gettoken com 0:0, parse(",")
{txt} 32{com}.         gettoken altNull3 0:0, parse(",")
{txt} 33{com}.         gettoken com 0:0, parse(",")
{txt} 34{com}.         gettoken altNull4 0:0, parse(",")
{txt} 35{com}.         
.         tempname null tempPi tempDelta tempPiVar tempDeltaVar tempCovar fileName
{txt} 36{com}.         
.         
.         if("`c(os)'"=="Windows"){c -(}
{txt} 37{com}.                 local tableSaveDir = "Tables\"
{txt} 38{com}.                 local plotSaveDir = "Plots\"
{txt} 39{com}.                 local pythonSaveDir = "PythonScripts\"
{txt} 40{com}.         {c )-}
{txt} 41{com}.         else{c -(}
{txt} 42{com}.                 local tableSaveDir = "Tables/"
{txt} 43{com}.                 local plotSaveDir = "Plots/"
{txt} 44{com}.                 local pythonSaveDir = "PythonScripts/"
{txt} 45{com}.         {c )-}
{txt} 46{com}.         
.         local fileName = "`tableSaveDir'iv-"+"`modelTitle'"+".xlsx"
{txt} 47{com}.         
.         di "`fsOut'"
{txt} 48{com}.         di "`rfOut'"
{txt} 49{com}.         di "`fsControls'"
{txt} 50{com}.         di "`rfControls'"
{txt} 51{com}.         di "`treatControl'"
{txt} 52{com}.         di "`absorbVars'"
{txt} 53{com}.         
.         jointEstimateFWL `fsOut', `rfOut', `fsControls', `rfControls', `treatControl', `absorbVars', `clusterVar', `treatmentVar', `modelTitle'
{txt} 54{com}.         return list
{txt} 55{com}.         
.         scalar `tempPi' = `r(pi)'
{txt} 56{com}.         scalar `tempDelta' = `r(delta)'
{txt} 57{com}.         scalar `tempPiVar' = `r(piVar)'
{txt} 58{com}.         scalar `tempDeltaVar' = `r(deltaVar)'
{txt} 59{com}.         scalar `tempCovar' = `r(covar)'
{txt} 60{com}.         
.         python script "`pythonSaveDir'calculateARStat.py", args(`tempPi' `tempDelta' `tempPiVar' `tempDeltaVar' `tempCovar' `nullLow' `nullDelta' `nullHigh' `modelTitle')
{txt} 61{com}.         
.         putexcel set "`fileName'", sheet("JointResults") modify
{txt} 62{com}.         
.         local primaryNullString = string(`primaryNull', "%2.1f")
{txt} 63{com}.         local altNullString = string(`altNull', "%2.1f")
{txt} 64{com}.         
.         qui putexcel B1 = `r(pi)'
{txt} 65{com}.         qui putexcel B2 = `r(delta)'
{txt} 66{com}.         qui putexcel B3 = `r(piVar)'
{txt} 67{com}.         qui putexcel B4 = `r(deltaVar)'
{txt} 68{com}.         qui putexcel B5 = `r(covar)'
{txt} 69{com}.         qui putexcel B6 = `r(covarHigh)'
{txt} 70{com}.         qui putexcel B7 = `r(covarLow)'
{txt} 71{com}.         qui putexcel B8 = `r(piVarUncorrected)'
{txt} 72{com}.         qui putexcel B9 = `r(deltaVarUncorrected)'
{txt} 73{com}.         qui putexcel B10 = `r(covarUncorrected)'
{txt} 74{com}.         qui putexcel B11 = `r(fsCorrection)'
{txt} 75{com}.         qui putexcel B12 = `r(rfCorrection)'
{txt} 76{com}.         qui putexcel B13 = `r(N)'
{txt} 77{com}.         qui putexcel B14 = `r(nClust)'
{txt} 78{com}.         qui putexcel B15 = `r(fsK)'
{txt} 79{com}.         qui putexcel B16 = `r(rfK)'
{txt} 80{com}.         
.         qui putexcel A1 = "pi"
{txt} 81{com}.         qui putexcel A2 = "delta"
{txt} 82{com}.         qui putexcel A3 = "pi variance"
{txt} 83{com}.         qui putexcel A4 = "delta variance"
{txt} 84{com}.         qui putexcel A5 = "pi-delta covariance"
{txt} 85{com}.         qui putexcel A6 = "pi-delta covariance high"
{txt} 86{com}.         qui putexcel A7 = "pi-delta covariance low"
{txt} 87{com}.         qui putexcel A8 = "pi variance uncorrected"
{txt} 88{com}.         qui putexcel A9 = "delta variance uncorrected"
{txt} 89{com}.         qui putexcel A10 = "pi-delta covariance uncorrected"
{txt} 90{com}.         qui putexcel A11 = "first stage finite-sample correction"
{txt} 91{com}.         qui putexcel A12 = "reduced form finite-sample correction"
{txt} 92{com}.         qui putexcel A13 = "N"
{txt} 93{com}.         qui putexcel A14 = "N Clusters"
{txt} 94{com}.         qui putexcel A15 = "first stage k"
{txt} 95{com}.         qui putexcel A16 = "reduced form k"
{txt} 96{com}.         qui putexcel A17 = "AR(Beta=`primaryNullString')"
{txt} 97{com}.         qui putexcel A18 = "P-Value(Beta=`primaryNullString')"
{txt} 98{com}.         qui putexcel A19 = "beta"
{txt} 99{com}.         qui putexcel A20 = "AR(Beta=`altNullString')"
{txt}100{com}.         qui putexcel A21 = "P-Value(Beta=`altNullString')"
{txt}101{com}.         qui putexcel A22 = "AR(Beta=`altNull2')"
{txt}102{com}.         qui putexcel A23 = "P-Value(Beta=`altNull2')"
{txt}103{com}.         qui putexcel A24 = "AR(Beta=`altNull3')"
{txt}104{com}.         qui putexcel A25 = "P-Value(Beta=`altNull3')"
{txt}105{com}.         qui putexcel A26 = "AR(Beta=`altNull4')"
{txt}106{com}.         qui putexcel A27 = "P-Value(Beta=`altNull4')"
{txt}107{com}.         
.         
.         
.         testNull `tempPi' `tempDelta' `tempPiVar' `tempDeltaVar' `tempCovar' `primaryNull'
{txt}108{com}.         
.         qui putexcel B17 = `r(arStat)'
{txt}109{com}.         qui putexcel B18 = `r(pVal)'
{txt}110{com}.         qui putexcel B19 = `r(beta)'
{txt}111{com}.         
.         testNull `tempPi' `tempDelta' `tempPiVar' `tempDeltaVar' `tempCovar' `altNull'
{txt}112{com}.         qui putexcel B20 = `r(arStat)'
{txt}113{com}.         qui putexcel B21 = `r(pVal)'
{txt}114{com}.         
.         testNull `tempPi' `tempDelta' `tempPiVar' `tempDeltaVar' `tempCovar' `altNull2'
{txt}115{com}.         qui putexcel B22 = `r(arStat)'
{txt}116{com}.         qui putexcel B23 = `r(pVal)'
{txt}117{com}.         
.         if("`altNull2'"!="`altNull3'"){c -(}
{txt}118{com}.                 qui putexcel A24 = "AR(Beta=`altNull3')"
{txt}119{com}.                 qui putexcel A25 = "P-Value(Beta=`altNull3')"
{txt}120{com}.                 
.                 testNull `tempPi' `tempDelta' `tempPiVar' `tempDeltaVar' `tempCovar' `altNull3'
{txt}121{com}.                 qui putexcel B24 = `r(arStat)'
{txt}122{com}.                 qui putexcel B25 = `r(pVal)'
{txt}123{com}.         {c )-}
{txt}124{com}.         if("`altNull3'"!="`altNull4'"){c -(}
{txt}125{com}.                 qui putexcel A26 = "AR(Beta=`altNull4')"
{txt}126{com}.                 qui putexcel A27 = "P-Value(Beta=`altNull4')"
{txt}127{com}.                 
.                 testNull `tempPi' `tempDelta' `tempPiVar' `tempDeltaVar' `tempCovar' `altNull4'
{txt}128{com}.                 qui putexcel B26 = `r(arStat)'
{txt}129{com}.                 qui putexcel B27 = `r(pVal)'
{txt}130{com}.         {c )-}
{txt}131{com}.         
. 
. end
{txt}
{com}. 
. //Construct table for LaTex output
. program constructTable
{txt}  1{com}.         version 16.1
{txt}  2{com}.         
.         gettoken tableLabel 0:0, parse(";")
{txt}  3{com}.         gettoken com 0:0, parse(";")
{txt}  4{com}.         gettoken outcomeLabel 0:0, parse(";")
{txt}  5{com}.         gettoken com 0:0, parse(";")
{txt}  6{com}.         gettoken models 0:0, parse(";")
{txt}  7{com}.         gettoken com 0:0, parse(";")
{txt}  8{com}.         gettoken modelTitles 0:0, parse(";")
{txt}  9{com}.         gettoken com 0:0, parse(";")
{txt} 10{com}.         gettoken primaryNull 0:0, parse(";")
{txt} 11{com}.         gettoken com 0:0, parse(";")
{txt} 12{com}.         gettoken altNull 0:0, parse(";")
{txt} 13{com}.         gettoken com 0:0, parse(";")
{txt} 14{com}.         gettoken altNull2 0:0, parse(";")
{txt} 15{com}.         gettoken com 0:0, parse(";")
{txt} 16{com}.         gettoken altNull3 0:0, parse(";")
{txt} 17{com}.         gettoken com 0:0, parse(";")
{txt} 18{com}.         gettoken altNull4 0:0, parse(";")
{txt} 19{com}.         
. 
.         if("`c(os)'"=="Windows"){c -(}
{txt} 20{com}.                 local tableSaveDir = "Tables\"
{txt} 21{com}.                 local plotSaveDir = "Plots\"
{txt} 22{com}.                 local pythonSaveDir = "PythonScripts\"
{txt} 23{com}.         {c )-}
{txt} 24{com}.         else{c -(}
{txt} 25{com}.                 local tableSaveDir = "Tables/"
{txt} 26{com}.                 local plotSaveDir = "Plots/"
{txt} 27{com}.                 local pythonSaveDir = "PythonScripts/"
{txt} 28{com}.         {c )-}
{txt} 29{com}.         
.         local i = 1
{txt} 30{com}.         
.         local floatFormat = "%04.3f"
{txt} 31{com}.         
.         foreach model in `models'{c -(}
{txt} 32{com}.                 di "`model'"
{txt} 33{com}.                 preserve
{txt} 34{com}.                 
.                 clear
{txt} 35{com}.                 
.                 qui import excel stat=A arg1=B arg2=C arg3=D arg4=E using "`tableSaveDir'iv.xlsx", sheet("`model'") cellrange(A1:E29)
{txt} 36{com}.         
.         
.                 gen y = 1
{txt} 37{com}.                 gen x = 1
{txt} 38{com}.                 
.                 qui reg y x
{txt} 39{com}.                 qui eststo `model'
{txt} 40{com}.                 
.                 estadd local groupFE = "Y"
{txt} 41{com}.                 estadd local timeFE = "Y"
{txt} 42{com}.                 estadd local timeTrend = "Y"
{txt} 43{com}.                 estadd local commonControls = "Y"
{txt} 44{com}.                 
.                 
.                 //Geta Beta point estimate
.                 qui sum arg1 if stat=="beta"
{txt} 45{com}.                 qui estadd local betaPoint = string(round(r(mean), .001), "`floatFormat'")
{txt} 46{com}.                 qui estadd local modelNum = "(`i')"
{txt} 47{com}.                 
.                 if(`i'==1){c -(}
{txt} 48{com}.                         qui estadd local dsc = "None"
{txt} 49{com}.                 {c )-} 
{txt} 50{com}.                 else if(`i'==2){c -(}
{txt} 51{com}.                         qui estadd local dsc = "Documented"
{txt} 52{com}.                 {c )-} 
{txt} 53{com}.                 else if(`i'==3){c -(}
{txt} 54{com}.                         qui estadd local dsc = "\makecell{c -(}Large \nextline Undocumented{c )-}"
{txt} 55{com}.                 {c )-} 
{txt} 56{com}.                 else if(`i'==4){c -(}
{txt} 57{com}.                         qui estadd local dsc = "\makecell{c -(}Small \nextline Undocumented{c )-}"
{txt} 58{com}.                 {c )-}
{txt} 59{com}.                 
.                 local i = `i'+1
{txt} 60{com}.                 
.                 local floatFormat = "%04.3f"
{txt} 61{com}.                 
.                 //Get P-Value and Stars for third alternate null (if appropriate)
.                 if("`tableLabel'"== "GasUseiv" || "`tableLabel'"=="GasUsePerCapitaiv"){c -(}
{txt} 62{com}.                         //Get primary null hypothesis test info
.                         //Get AR-Stat primary null
.                         
.                         qui sum arg1 if stat=="P-Value(Beta=11.0)"
{txt} 63{com}.                         qui local tempP = r(mean)
{txt} 64{com}.                         //Get P-Value and Stars for primary null
.                         qui estadd local primaryP = string(round(r(mean),0.001), "`floatFormat'")
{txt} 65{com}.                         qui sum arg1 if stat=="AR(Beta=11.0)"
{txt} 66{com}.                         //Determine Stars for primary null
.                         qui local stars = ""
{txt} 67{com}.                         
.                         if(`tempP'<0.01){c -(}
{txt} 68{com}.                                 local stars = "***"
{txt} 69{com}.                         {c )-}       
{txt} 70{com}.                         else if(`tempP'<0.05){c -(}
{txt} 71{com}.                                 local stars = "**"
{txt} 72{com}.                         {c )-}
{txt} 73{com}.                         else if(`tempP'<0.1){c -(}
{txt} 74{com}.                                 local stars = "*"
{txt} 75{com}.                         {c )-}
{txt} 76{com}.                         qui estadd local primaryARStat = string(round(r(mean),.001), "`floatFormat'")+"`stars'"
{txt} 77{com}.                         qui sum arg1 if stat=="P-Value(Beta=9.7)"
{txt} 78{com}.                         qui local tempP = r(mean)
{txt} 79{com}.                         //Get P-Value and Stars for primary null
.                         qui estadd local altP = string(round(r(mean),0.001), "`floatFormat'")
{txt} 80{com}.                         
.                         qui sum arg1 if stat=="AR(Beta=9.7)"
{txt} 81{com}.                         //Determine Stars for primary null
.                         qui local stars = ""
{txt} 82{com}.                         
.                         if(`tempP'<0.01){c -(}
{txt} 83{com}.                                 local stars = "***"
{txt} 84{com}.                         {c )-}       
{txt} 85{com}.                         else if(`tempP'<0.05){c -(}
{txt} 86{com}.                                 local stars = "**"
{txt} 87{com}.                         {c )-}
{txt} 88{com}.                         else if(`tempP'<0.1){c -(}
{txt} 89{com}.                                 local stars = "*"
{txt} 90{com}.                         {c )-}
{txt} 91{com}.                         qui estadd local altARStat = string(round(r(mean),.001), "`floatFormat'")+"`stars'"
{txt} 92{com}.                         //Get alternate null hypothesis test info
.                         //Get AR-Stat alternate null
.                         qui sum arg1 if stat=="P-Value(Beta=1)"
{txt} 93{com}.                         qui local tempP = r(mean)
{txt} 94{com}.                         //Get P-Value and Stars for alternate null
.                         qui estadd local altP2 = string(round(r(mean),0.001), "`floatFormat'")
{txt} 95{com}.                         qui sum arg1 if stat=="AR(Beta=1)"
{txt} 96{com}.                         //Determine Stars for alternate null
.                         qui local stars = ""
{txt} 97{com}.                         
.                         if(`tempP'<0.01){c -(}
{txt} 98{com}.                                 local stars = "***"
{txt} 99{com}.                         {c )-}       
{txt}100{com}.                         else if(`tempP'<0.05){c -(}
{txt}101{com}.                                 local stars = "**"
{txt}102{com}.                         {c )-}
{txt}103{com}.                         else if(`tempP'<0.1){c -(}
{txt}104{com}.                                 local stars = "*"
{txt}105{com}.                         {c )-}
{txt}106{com}.                         qui estadd local altARStat2 = string(round(r(mean),.001), "`floatFormat'")+"`stars'"
{txt}107{com}.                         
.                         //Get P-Value and Stars for second alternate null
.                         qui sum arg1 if stat=="P-Value(Beta=-4.8)"
{txt}108{com}.                         qui local tempP = r(mean)
{txt}109{com}.                         qui estadd local altP3 = string(round(r(mean),0.001), "`floatFormat'")
{txt}110{com}.                         qui sum arg1 if stat=="AR(Beta=-4.8)"
{txt}111{com}.                         //Determine Stars for alternate null
.                         qui local stars = ""
{txt}112{com}.                         
.                         if(`tempP'<0.01){c -(}
{txt}113{com}.                                 local stars = "***"
{txt}114{com}.                         {c )-}       
{txt}115{com}.                         else if(`tempP'<0.05){c -(}
{txt}116{com}.                                 local stars = "**"
{txt}117{com}.                         {c )-}
{txt}118{com}.                         else if(`tempP'<0.1){c -(}
{txt}119{com}.                                 local stars = "*"
{txt}120{com}.                         {c )-}
{txt}121{com}.                         qui estadd local altARStat3 = string(round(r(mean),.001), "`floatFormat'")+"`stars'"
{txt}122{com}.                         
.                         //Get P-Value and Stars for second alternate null
.                         qui sum arg1 if stat=="P-Value(Beta=-6.1)"
{txt}123{com}.                         qui local tempP = r(mean)
{txt}124{com}.                         qui estadd local altP4 = string(round(r(mean),0.001), "`floatFormat'")
{txt}125{com}.                         qui sum arg1 if stat=="AR(Beta=-6.1)"
{txt}126{com}.                         //Determine Stars for alternate null
.                         qui local stars = ""
{txt}127{com}.                         
.                         if(`tempP'<0.01){c -(}
{txt}128{com}.                                 local stars = "***"
{txt}129{com}.                         {c )-}       
{txt}130{com}.                         else if(`tempP'<0.05){c -(}
{txt}131{com}.                                 local stars = "**"
{txt}132{com}.                         {c )-}
{txt}133{com}.                         else if(`tempP'<0.1){c -(}
{txt}134{com}.                                 local stars = "*"
{txt}135{com}.                         {c )-}
{txt}136{com}.                         qui estadd local altARStat4 = string(round(r(mean),.001), "`floatFormat'")+"`stars'"
{txt}137{com}.                 {c )-}
{txt}138{com}.                 else{c -(}
{txt}139{com}.                         
.                         //Get primary null hypothesis test info
.                         //Get AR-Stat primary null
.                         
.                         qui sum arg1 if stat=="P-Value(Beta=1.6)"
{txt}140{com}.                         qui local tempP = r(mean)
{txt}141{com}.                         //Get P-Value and Stars for primary null
.                         qui estadd local primaryP = string(round(r(mean),0.001), "`floatFormat'")
{txt}142{com}.                         qui sum arg1 if stat=="AR(Beta=1.6)"
{txt}143{com}.                         //Determine Stars for primary null
.                         qui local stars = ""
{txt}144{com}.                         
.                         if(`tempP'<0.01){c -(}
{txt}145{com}.                                 local stars = "***"
{txt}146{com}.                         {c )-}       
{txt}147{com}.                         else if(`tempP'<0.05){c -(}
{txt}148{com}.                                 local stars = "**"
{txt}149{com}.                         {c )-}
{txt}150{com}.                         else if(`tempP'<0.1){c -(}
{txt}151{com}.                                 local stars = "*"
{txt}152{com}.                         {c )-}
{txt}153{com}.                         qui estadd local primaryARStat = string(round(r(mean),.001), "`floatFormat'")+"`stars'"
{txt}154{com}.                         //Get alternate null hypothesis test info
.                         //Get AR-Stat alternate null
.                         qui sum arg1 if stat=="P-Value(Beta=1.0)"
{txt}155{com}.                         qui local tempP = r(mean)
{txt}156{com}.                         //Get P-Value and Stars for alternate null
.                         qui estadd local altP = string(round(r(mean),0.001), "`floatFormat'")
{txt}157{com}.                         qui sum arg1 if stat=="AR(Beta=1.0)"
{txt}158{com}.                         //Determine Stars for alternate null
.                         qui local stars = ""
{txt}159{com}.                         
.                         if(`tempP'<0.01){c -(}
{txt}160{com}.                                 local stars = "***"
{txt}161{com}.                         {c )-}       
{txt}162{com}.                         else if(`tempP'<0.05){c -(}
{txt}163{com}.                                 local stars = "**"
{txt}164{com}.                         {c )-}
{txt}165{com}.                         else if(`tempP'<0.1){c -(}
{txt}166{com}.                                 local stars = "*"
{txt}167{com}.                         {c )-}
{txt}168{com}.                         qui estadd local altARStat = string(round(r(mean),.001), "`floatFormat'")+"`stars'"
{txt}169{com}.                         
.                         //Get alternate null hypothesis test info
.                         //Get AR-Stat alternate null
.                         qui sum arg1 if stat=="P-Value(Beta=.3)"
{txt}170{com}.                         qui local tempP = r(mean)
{txt}171{com}.                         //Get P-Value and Stars for alternate null
.                         qui estadd local altP2 = string(round(r(mean),0.001), "`floatFormat'")
{txt}172{com}.                         qui sum arg1 if stat=="AR(Beta=.3)"
{txt}173{com}.                         //Determine Stars for alternate null
.                         qui local stars = ""
{txt}174{com}.                         
.                         if(`tempP'<0.01){c -(}
{txt}175{com}.                                 local stars = "***"
{txt}176{com}.                         {c )-}       
{txt}177{com}.                         else if(`tempP'<0.05){c -(}
{txt}178{com}.                                 local stars = "**"
{txt}179{com}.                         {c )-}
{txt}180{com}.                         else if(`tempP'<0.1){c -(}
{txt}181{com}.                                 local stars = "*"
{txt}182{com}.                         {c )-}
{txt}183{com}.                         qui estadd local altARStat2 = string(round(r(mean),.001), "`floatFormat'")+"`stars'"
{txt}184{com}.                         
.                         //Get alternate null hypothesis test info
.                         //Get AR-Stat alternate null
.                         qui sum arg1 if stat=="P-Value(Beta=0)"
{txt}185{com}.                         qui local tempP = r(mean)
{txt}186{com}.                         //Get P-Value and Stars for alternate null
.                         qui estadd local altP3 = string(round(r(mean),0.001), "`floatFormat'")
{txt}187{com}.                         qui sum arg1 if stat=="AR(Beta=0)"
{txt}188{com}.                         //Determine Stars for alternate null
.                         qui local stars = ""
{txt}189{com}.                         
.                         if(`tempP'<0.01){c -(}
{txt}190{com}.                                 local stars = "***"
{txt}191{com}.                         {c )-}       
{txt}192{com}.                         else if(`tempP'<0.05){c -(}
{txt}193{com}.                                 local stars = "**"
{txt}194{com}.                         {c )-}
{txt}195{com}.                         else if(`tempP'<0.1){c -(}
{txt}196{com}.                                 local stars = "*"
{txt}197{com}.                         {c )-}
{txt}198{com}.                         qui estadd local altARStat3 = string(round(r(mean),.001), "`floatFormat'")+"`stars'"
{txt}199{com}.                         
.                         //Get P-Value and Stars for second alternate null
.                         qui sum arg1 if stat=="P-Value(Beta=-2.5)"
{txt}200{com}.                         qui local tempP = r(mean)
{txt}201{com}.                         qui estadd local altP4 = string(round(r(mean),0.001), "`floatFormat'")
{txt}202{com}.                         qui sum arg1 if stat=="AR(Beta=-2.5)"
{txt}203{com}.                         //Determine Stars for alternate null
.                         qui local stars = ""
{txt}204{com}.                         
.                         if(`tempP'<0.01){c -(}
{txt}205{com}.                                 local stars = "***"
{txt}206{com}.                         {c )-}       
{txt}207{com}.                         else if(`tempP'<0.05){c -(}
{txt}208{com}.                                 local stars = "**"
{txt}209{com}.                         {c )-}
{txt}210{com}.                         else if(`tempP'<0.1){c -(}
{txt}211{com}.                                 local stars = "*"
{txt}212{com}.                         {c )-}
{txt}213{com}.                         qui estadd local altARStat4 = string(round(r(mean),.001), "`floatFormat'")+"`stars'"
{txt}214{com}.                 {c )-}
{txt}215{com}.                 //Get N
.                 qui sum arg1 if stat=="N"
{txt}216{com}.                 qui estadd local obs = string(round(r(mean)), "%9.0fc")
{txt}217{com}.                 
.                 //Get 95% Confidence set
.                 local floatFormat = "%3.2f"
{txt}218{com}.                 qui sum arg3 if stat=="95% Confidence Set"
{txt}219{com}.                 if(r(N)==1){c -(}
{txt}220{com}.                         qui sum arg2 if stat=="95% Confidence Set"
{txt}221{com}.                         local lPoint = string(round(r(mean),.01), "`floatFormat'")
{txt}222{com}.                         sum arg3 if stat=="95% Confidence Set"
{txt}223{com}.                         qui local rPoint = string(round(r(mean),.01), "`floatFormat'")
{txt}224{com}.                         
.                         qui estadd local cs95 "\makecell{c -(}(-$\infty$, $`lPoint']$; \nextline $[`rPoint'$, $\infty$){c )-}"
{txt}225{com}.                         
.                 {c )-}
{txt}226{com}.                 else{c -(}
{txt}227{com}.                         qui sum arg1 if stat=="95% Confidence Set"
{txt}228{com}.                         if(r(N)==1){c -(}
{txt}229{com}.                                 local lPoint = string(round(r(mean),.01), "`floatFormat'")
{txt}230{com}.                         {c )-}
{txt}231{com}.                         else{c -(}
{txt}232{com}.                                 local lPoint = "-$\infty$"
{txt}233{com}.                         {c )-}
{txt}234{com}.                         qui sum arg2 if stat=="95% Confidence Set"
{txt}235{com}.                         if(r(N)==1){c -(}
{txt}236{com}.                                 local rPoint = string(round(r(mean),.01), "`floatFormat'")
{txt}237{com}.                         {c )-}
{txt}238{com}.                         else{c -(}
{txt}239{com}.                                 local rPoint = "$\infty$"
{txt}240{com}.                         {c )-}
{txt}241{com}.                         
.                         if("`lPoint'"=="-$\infty$" & "`rPoint'"=="$\infty$"){c -(}
{txt}242{com}.                                 qui estadd local cs95 = "(`lPoint', `rPoint')"
{txt}243{com}.                         {c )-}
{txt}244{com}.                         else{c -(}
{txt}245{com}.                                 qui estadd local cs95 = "[`lPoint', `rPoint']"
{txt}246{com}.                         {c )-}
{txt}247{com}.                         
.                         
.                         
.                 {c )-}
{txt}248{com}.                 
.                 //Get 90% Confidence Set
.                 qui sum arg3 if stat=="90% Confidence Set"
{txt}249{com}.                 if(r(N)==1){c -(}
{txt}250{com}.                         qui sum arg2 if stat=="90% Confidence Set"
{txt}251{com}.                         local lPoint = string(round(r(mean),.01))
{txt}252{com}.                         qui sum arg3 if stat=="90% Confidence Set"
{txt}253{com}.                         local rPoint = string(round(r(mean),.01))
{txt}254{com}.                         
.                         qui estadd local cs90 "(-$\infty$, `lPoint']; [`rPoint', $\infty$)"
{txt}255{com}.                         
.                 {c )-}
{txt}256{com}.                 else{c -(}
{txt}257{com}.                         qui sum arg1 if stat=="90% Confidence Set"
{txt}258{com}.                         if(r(N)==1){c -(}
{txt}259{com}.                                 local lPoint = string(round(r(mean),.01))
{txt}260{com}.                         {c )-}
{txt}261{com}.                         else{c -(}
{txt}262{com}.                                 local lPoint = "-$\infty$"
{txt}263{com}.                         {c )-}
{txt}264{com}.                         qui sum arg2 if stat=="90% Confidence Set"
{txt}265{com}.                         if(r(N)==1){c -(}
{txt}266{com}.                                 local rPoint = string(round(r(mean),.01))
{txt}267{com}.                         {c )-}
{txt}268{com}.                         else{c -(}
{txt}269{com}.                                 local rPoint = "$\infty$"
{txt}270{com}.                         {c )-}
{txt}271{com}.                         
.                         qui estadd local cs90 = "[`lPoint', `rPoint']"
{txt}272{com}.                         
.                 {c )-}
{txt}273{com}.                 
.                 
.                 
.                 
.                 restore
{txt}274{com}.         {c )-}
{txt}275{com}.         
.         //Output Table
.         
.         if("`c(os)'"=="Windows"){c -(}
{txt}276{com}.                 local tableSaveDir = "Tables\IV\"
{txt}277{com}.                 local plotSaveDir = "Plots\"
{txt}278{com}.                 local pythonSaveDir = "PythonScripts\"
{txt}279{com}.         {c )-}
{txt}280{com}.         else{c -(}
{txt}281{com}.                 local tableSaveDir = "Tables/IV/"
{txt}282{com}.                 local plotSaveDir = "Plots/"
{txt}283{com}.                 local pythonSaveDir = "PythonScripts/"
{txt}284{com}.         {c )-}
{txt}285{com}.         
.         
.         if("`tableLabel'"=="VMTiv"){c -(}
{txt}286{com}.                 local titleOutcome = "Log Registrations on Log VMT"
{txt}287{com}.                 local noteString = "\hline \hline \end{c -(}tabular{c )-} \vspace{c -(}0.2cm{c )-} \begin{c -(}tablenotes{c )-} \begin{c -(}spacing{c )-}{c -(}0{c )-} \begin{c -(}footnotesize{c )-} \item \textbf{c -(}Notes:{c )-} The top panel of this table presents IV estimates and 95\% confidence sets robust to weak instruments of the linear relationship between log vehicle-miles travelled (VMT) and log vehicle registrations.  The bottom panel presents Anderson-Rubin chi-squared statistics along with p-values for different null hypotheses pertaining to the parameter estimated in the top panel.  The unit of observation is state-year.  All regressions include state fixed effects, year fixed effects and state-specific linear time trends. The four specifications pertaining to different levels of ``Data Source Controls'' (DSCs) and control specifications are documented in Table \cref{c -(}ssec:Spec{c )-}. Confidence sets are based on standard errors clustered by state. * p\textless 0.1, ** p\textless 0.05, *** p\textless 0.01 \end{c -(}footnotesize{c )-} \end{c -(}spacing{c )-} \end{c -(}tablenotes{c )-} \end{c -(}table{c )-}"
{txt}288{com}.         {c )-} 
{txt}289{com}.         else if("`tableLabel'"=="VMTPerCapitaiv"){c -(}
{txt}290{com}.                 local titleOutcome = "Log Registrations per Capita on Log VMT per Capita"
{txt}291{com}.                 local noteString = "\hline \hline \end{c -(}tabular{c )-} \vspace{c -(}0.2cm{c )-} \begin{c -(}tablenotes{c )-} \begin{c -(}spacing{c )-}{c -(}0{c )-} \begin{c -(}footnotesize{c )-} \item \textbf{c -(}Notes:{c )-} The top panel of this table presents IV estimates and 95\% confidence sets robust to weak instruments of the linear relationship between log vehicle-miles travelled (VMT) per capita and log vehicle registrations per capita.  The bottom panel presents Anderson-Rubin chi-squared statistics along with p-values for different null hypotheses pertaining to the parameter estimated in the top panel.  The unit of observation is state-year. The four specifications pertaining to different levels of ``Data Source Controls'' (DSCs) and control specifications are documented in Table \cref{c -(}ssec:Spec{c )-}. Confidence sets are based on standard errors clustered by state. * p\textless 0.1, ** p\textless 0.05, *** p\textless 0.01 \end{c -(}footnotesize{c )-} \end{c -(}spacing{c )-} \end{c -(}tablenotes{c )-} \end{c -(}table{c )-}"
{txt}292{com}.         {c )-}
{txt}293{com}.         else if("`tableLabel'"=="GasUseiv"){c -(}
{txt}294{com}.                 local titleOutcome = "Log Registrations on Log Highway Gas Use"
{txt}295{com}.                 local noteString = "\hline \hline \end{c -(}tabular{c )-} \vspace{c -(}0.2cm{c )-} \begin{c -(}tablenotes{c )-} \begin{c -(}spacing{c )-}{c -(}0{c )-} \begin{c -(}footnotesize{c )-} \item \textbf{c -(}Notes:{c )-} The top panel of this table presents IV estimates and 95\% confidence sets robust to weak instruments of the linear relationship between log highway gas use and log vehicle registrations.  The bottom panel presents Anderson-Rubin chi-squared statistics along with p-values for different null hypotheses pertaining to the parameter estimated in the top panel. The unit of observation is state-year. The four specifications pertaining to different levels of ``Data Source Controls'' (DSCs) and control specifications are documented in Table \cref{c -(}ssec:Spec{c )-}. Confidence sets are based on standard errors clustered by state. * p\textless 0.1, ** p\textless 0.05, *** p\textless 0.01 \end{c -(}footnotesize{c )-} \end{c -(}spacing{c )-} \end{c -(}tablenotes{c )-} \end{c -(}table{c )-}"
{txt}296{com}.         {c )-}
{txt}297{com}.         else if("`tableLabel'"=="GasUsePerCapitaiv"){c -(}
{txt}298{com}.                 local titleOutcome = "Log Registrations per Capita on Log Highway Gas Use per Capita"
{txt}299{com}.                 local noteString = "\hline \hline \end{c -(}tabular{c )-} \vspace{c -(}0.2cm{c )-} \begin{c -(}tablenotes{c )-} \begin{c -(}spacing{c )-}{c -(}0{c )-} \begin{c -(}footnotesize{c )-} \item \textbf{c -(}Notes:{c )-} The top panel of this table presents IV estimates and 95\% confidence sets robust to weak instruments of the linear relationship between log highway gas use per capita and log vehicle registrations per capita.  The bottom panel presents Anderson-Rubin chi-squared statistics along with p-values for different null hypotheses pertaining to the parameter estimated in the top panel.  The unit of observation is state-year.  The four specifications pertaining to different levels of ``Data Source Controls'' (DSCs) and control specifications are documented in Table \cref{c -(}ssec:Spec{c )-}. Confidence sets are based on standard errors clustered by state. * p\textless 0.1, ** p\textless 0.05, *** p\textless 0.01 \end{c -(}footnotesize{c )-} \end{c -(}spacing{c )-} \end{c -(}tablenotes{c )-} \end{c -(}table{c )-}"
{txt}300{com}.         {c )-}
{txt}301{com}.         
.         local saveFile = "`tableSaveDir'"+"`tableLabel'"+".tex"
{txt}302{com}.         
.         local fmtDiD = `"drop(*) nocon label compress starlevels(* 0.1 ** 0.05 *** 0.01) nodepvar nomtitle nonumbers not nostar noline"'
{txt}303{com}.         
.         
.         
.         
.         if("`tableLabel'"== "GasUseiv" || "`tableLabel'"=="GasUsePerCapitaiv"){c -(}
{txt}304{com}.                 local greekLetter = "\gamma"
{txt}305{com}.                 
.                 
.                 
.                 esttab `models' using "`saveFile'", drop(*) stats(panel1 modelNum betaPoint cs95 dsc groupFE timeFE timeTrend commonControls obs panel2 primaryARStat primaryP space1 altARStat altP space2 altARStat2 altP2 space3 altARStat3 altP3 space4 altARStat4 altP4, labels( "\hline \hline \multicolumn{c -(}5{c )-}{c -(}l{c )-}{c -(}\textit{c -(}Panel A: IV Estimates and Robust 95\% Confidence Intervals{c )-}{c )-} \\" "\multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}Dep. Var.: Log Number of Vehicle Registrations{c )-} \\ " "$`greekLetter'$" "95\% Conf. Set" "\makecell[l]{c -(}Data Source \nextline Controls{c )-}" "State Fixed Effects" "Year Fixed Effects" "\makecell[l]{c -(}State-Specific Linear \\ Time Trends{c )-}" "Common Controls" "Number of Obs." "\hline \hline \multicolumn{c -(}5{c )-}{c -(}l{c )-}{c -(}\textit{c -(}Panel B: Anderson-Robin Test Statistics and P-Values{c )-}{c )-} \\" " \multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}\underline{c -(}\$ H_{c -(}0{c )-}:`greekLetter'=11\${c )-}{c )-} \\ AR Stat" "p-value" " " " \multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}\underline{c -(}\$ H_{c -(}0{c )-}:`greekLetter'=9.7\${c )-}{c )-} \\ AR Stat" "p-value" " " "\multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}\underline{c -(}\$ H_{c -(}0{c )-}:`greekLetter'=\$1{c )-}{c )-} \\ AR Stat" "p-value" " " "\multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}\underline{c -(}\$ H_{c -(}0{c )-}:`greekLetter'=\$-4.8{c )-}{c )-} \\ AR Stat" "p-value" " " "\multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}\underline{c -(}\$ H_{c -(}0{c )-}:`greekLetter'=\$-6.1{c )-}{c )-} \\ AR Stat" "p-value")) nostar nomtitle nonumbers not nolines title("Robust IV Estimates of `titleOutcome' \label{c -(}tab:`tableLabel'{c )-}") replace postfoot("`noteString'") sub(\_ _)
{txt}306{com}.                 
.         {c )-}
{txt}307{com}.         else{c -(}
{txt}308{com}.                 local greekLetter = "\beta"
{txt}309{com}.                 
.                 esttab `models' using "`saveFile'", drop(*) stats(panel1 modelNum betaPoint cs95 dsc groupFE timeFE timeTrend commonControls obs panel2 primaryARStat primaryP space1 altARStat altP space2 altARStat2 altP2 space3 altARStat3 altP3 space4 altARStat4 altP4, labels("\hline \hline \multicolumn{c -(}5{c )-}{c -(}l{c )-}{c -(}\textit{c -(}Panel A: IV Estimates and Robust 95\% Confidence Intervals{c )-}{c )-} \\" "\multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}Dep. Var.: Log Number of Vehicle Registrations{c )-} \\ " "$`greekLetter'$" "95\% Conf. Set" "\makecell[l]{c -(}Data Source \nextline Controls{c )-}" "State Fixed Effects" "Year Fixed Effects" "\makecell[l]{c -(}State-Specific Linear \\ Time Trends{c )-}" "Common Controls" "Number of Obs." "\hline \hline \multicolumn{c -(}5{c )-}{c -(}l{c )-}{c -(}\textit{c -(}Panel B: Anderson-Robin Test Statistics and P-Values{c )-}{c )-} \\" "\multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}\underline{c -(}\$ H_{c -(}0{c )-}:`greekLetter'=1.6\${c )-}{c )-} \\ AR Stat" "p-value" " " "\multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}\underline{c -(}\$ H_{c -(}0{c )-}:`greekLetter'=1\${c )-}{c )-} \\ AR Stat" "p-value" " " "\multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}\underline{c -(}\$ H_{c -(}0{c )-}:`greekLetter'=0.3\${c )-}{c )-} \\ AR Stat" "p-value" " " "\multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}\underline{c -(}\$ H_{c -(}0{c )-}:`greekLetter'=0\${c )-}{c )-} \\ AR Stat" "p-value" " " "\multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}\underline{c -(}\$ H_{c -(}0{c )-}:`greekLetter'=-2.5\${c )-}{c )-} \\ AR Stat" "p-value") fmt(%4.0fc)) nostar nomtitle nonumbers not nolines title("Robust IV Estimates of Log Registration on `titleOutcome' \label{c -(}tab:`tableLabel'{c )-}") replace postfoot("`noteString'") sub(\_ _)
{txt}310{com}. 
.                 
.         {c )-}
{txt}311{com}.         
.         
.         
.         
. end
{txt}
{com}. 
{txt}end of do-file

{com}. 
. // // //Execute Stata Do File to load and clean the data for VMT models
. do LoadDataVMT
{txt}
{com}. clear
{txt}
{com}. //Load Data for travel analysis
. 
. 
. 
. 
. if("`c(os)'"=="Windows"){c -(}
.         local dataFile = "CleanedData\FHWACleanV4.csv"
. {c )-}
{txt}
{com}. else{c -(}
.         local dataFile = "CleanedData/FHWACleanV4.csv"
. {c )-}
{txt}
{com}. 
. import delimited using "`dataFile'"
{res}{txt}(encoding automatically selected: ISO-8859-1)
{res}{text}(90 vars, 3,009 obs)

{com}. 
. //Add State Codes to all states
. sort state
{txt}
{com}. egen tempStateCode = mode(statecode), by(state)
{txt}
{com}. replace statecode = tempStateCode
{txt}(357 real changes made)

{com}. drop tempStateCode
{txt}
{com}. 
. //Label Variables
. label var logregistrations "Log Total Registrations"
{txt}
{com}. label var logvmt "Log VMT"
{txt}
{com}. label var loglicenseddrivers "Log Licensed Drivers" 
{txt}
{com}. label var logjointpopulation "Log Total Population" 
{txt}
{com}. label var logrealmeangasprice "Log Mean Gas Price" 
{txt}
{com}. label var logemployment  "Log Employment"
{txt}
{com}. label var logrealjointincome  "Log Total Income"
{txt}
{com}. label var logmetropop  "Log (1 + Metro Population)"
{txt}
{com}. label var lognonmetropop  "Log (1 + Non-Metro Population)"
{txt}
{com}. label var logmetrorealinc  "Log (1 + Metro Income)"
{txt}
{com}. label var lognonmetrorealinc  "Log (1 + Non-Metro Income)"
{txt}
{com}. label var logrealstategdp  "Log State GDP"
{txt}
{com}. label var logpopulation  "Log Population"
{txt}
{com}. label var logrealtotalincome  "Log Total Income"
{txt}
{com}. label var logroadmileage "Log Road Mileage"
{txt}
{com}. label var nosafetyind "Treatment"
{txt}
{com}. 
. 
. //Create Inverse Hyperbolic Sine Variables 
. gen asinhMetroInc = asinh(realmetroincome2018m)
{txt}(459 missing values generated)

{com}. gen asinhNonMetroInc = asinh(realnonmetroincome2018m)
{txt}(459 missing values generated)

{com}. 
. gen asinhMetroPop = asinh(metropopulation)
{txt}(459 missing values generated)

{com}. gen asinhNonMetroPop = asinh(nonmetropopulation)
{txt}(459 missing values generated)

{com}. 
. //Per capita model
. //construct outcome variable
. gen logRegPerCapita = logregistrations-log(metropopulation + nonmetropopulation)
{txt}(510 missing values generated)

{com}. gen logVMTPerCapita = logvmt-log(metropopulation + nonmetropopulation)
{txt}(510 missing values generated)

{com}. 
. //Label Asinh variables
. label var asinhMetroInc "Asinh(Metro Income)"
{txt}
{com}. label var asinhNonMetroInc "Asinh(Non-Metro Income)"
{txt}
{com}. 
. label var asinhMetroPop "Asinh(Metro Population)"
{txt}
{com}. label var asinhNonMetroPop "Asinh(Non-Metro Population)"
{txt}
{com}. 
. //Label treatment variables
. 
. label define nosafetyind 0 "No Treatment" 1 "Treatment"
{txt}
{com}. label values nosafetyind nosafetyind
{txt}
{com}. 
. 
. //Generate State Dummies
. egen stateGroup = group(state)
{txt}
{com}. 
. //Drop Datapoints that are replications of past data for registrations
. drop if statecode=="CO" & year==2006
{txt}(1 observation deleted)

{com}. drop if statecode=="IN" & (year==2006 | year==2007 | year==2009)
{txt}(3 observations deleted)

{com}. drop if statecode=="MT" & year==2005
{txt}(1 observation deleted)

{com}. drop if statecode=="NJ" & year==2008
{txt}(1 observation deleted)

{com}. drop if statecode=="PR" & (year==2002 | year==2003 | year==2005 | year==2008 | year==2009 | year==2010)
{txt}(0 observations deleted)

{com}. drop if statecode=="TX" & year==2009
{txt}(1 observation deleted)

{com}. drop if statecode=="IL" & year==2011
{txt}(1 observation deleted)

{com}. drop if statecode=="NH" & year==2012
{txt}(1 observation deleted)

{com}. drop if statecode=="NY" & year==2012
{txt}(1 observation deleted)

{com}. //Drop Datapoints that are replications of past data for VMT
. drop if statecode=="MO" & year == 2003
{txt}(1 observation deleted)

{com}. drop if statecode=="IN" & (year == 2004 | year==2009)
{txt}(1 observation deleted)

{com}. drop if statecode=="NV" & year == 2004
{txt}(1 observation deleted)

{com}. drop if statecode=="NH" & year == 2004
{txt}(1 observation deleted)

{com}. drop if statecode=="NY" & year == 2005
{txt}(1 observation deleted)

{com}. drop if statecode=="AZ" & year == 2009
{txt}(1 observation deleted)

{com}. drop if statecode=="WY" & year == 2010
{txt}(1 observation deleted)

{com}. drop if statecode=="PR" & (year == 2011 | year == 2012 | year == 2013 | year == 2015 | year == 2016)
{txt}(0 observations deleted)

{com}. 
. //Drop if data is prior to 1970
. drop if year<1970
{txt}(510 observations deleted)

{com}. 
. //Normalize differenece of outcome variables for identification of extreme points
. 
. sort stateGroup year
{txt}
{com}. xtset stateGroup year
{res}
{col 1}{txt:Panel variable: }{res:stateGroup}{txt: (unbalanced)}
{p 1 16 2}{txt:Time variable: }{res:year}{txt:, }{res:{bind:1970}}{txt: to }{res:{bind:2018}}{txt:, but with gaps}{p_end}
{txt}{col 10}Delta: {res}1 unit
{txt}
{com}. 
. gen DiffLogReg = d.logregistrations
{txt}(118 missing values generated)

{com}. gen DiffLogVMT = d.logvmt
{txt}(118 missing values generated)

{com}. gen DiffLogRegPerCapita = d.logRegPerCapita
{txt}(118 missing values generated)

{com}. gen DiffLogVMTPerCapita = d.logVMTPerCapita
{txt}(118 missing values generated)

{com}. 
. local normVarList = "DiffLogReg DiffLogVMT DiffLogRegPerCapita DiffLogVMTPerCapita"
{txt}
{com}. 
. sort stateGroup
{txt}
{com}. 
. foreach varToNorm in `normVarList'{c -(}
{txt}  2{com}.         
.         by stateGroup: egen tempMean = mean(`varToNorm')
{txt}  3{com}.         by stateGroup: egen tempSD = sd(`varToNorm')
{txt}  4{com}.         by stateGroup: egen tempNumData = count(`varToNorm')
{txt}  5{com}.         gen tempSE = tempSD/sqrt(tempNumData)
{txt}  6{com}.         
.         gen norm`varToNorm' = (`varToNorm'-tempMean)/tempSD
{txt}  7{com}.         
.         drop tempMean tempSD tempNumData tempSE
{txt}  8{com}.         
.         di "`varToNorm'"
{txt}  9{com}.         
. {c )-}
{txt}(118 missing values generated)
DiffLogReg
(118 missing values generated)
DiffLogVMT
(118 missing values generated)
DiffLogRegPerCapita
(118 missing values generated)
DiffLogVMTPerCapita

{com}. 
. //Generate Colorado Dummy
. gen coDum1 = 0
{txt}
{com}. gen coDum2 = 0
{txt}
{com}. replace coDum1 = 1 if statecode=="CO" & year>=2002 & year<=2009
{txt}(7 real changes made)

{com}. replace coDum2 = 1 if statecode=="CO" & year>=2010
{txt}(9 real changes made)

{com}. 
. drop if coDum1 == 1
{txt}(7 observations deleted)

{com}. 
. 
. //Generate dummy variable for data footnotes
. gen transactionDataDummy = 0
{txt}
{com}. 
. replace transactionDataDummy = 1 if statecode=="AR" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 2 if statecode=="GA" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 3 if statecode=="IA" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 4 if statecode=="IL" & year>=2012
{txt}(7 real changes made)

{com}. replace transactionDataDummy = 5 if statecode=="KY" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 6 if statecode=="LA" & year>=2012
{txt}(7 real changes made)

{com}. replace transactionDataDummy = 7 if statecode=="ME" & year>=2011 //Maine is a state with what looks to not have a consistent change
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 8 if statecode=="ME" & year>2014
{txt}(4 real changes made)

{com}. replace transactionDataDummy = 9 if statecode=="MI" & year>=2011 //Michigan is a state with what looks to not have a consistent change
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 10 if statecode=="MI" & year>2012
{txt}(6 real changes made)

{com}. replace transactionDataDummy = 11 if statecode=="MN" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 12 if statecode=="NV" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 13 if statecode=="OK" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 14 if statecode=="SD" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 15 if statecode=="TN" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 16 if statecode=="TX" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 17 if statecode=="WA" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 18 if statecode=="WI" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 19 if statecode=="WY" & year>=2011
{txt}(8 real changes made)

{com}. 
. 
. 
. 
. //Local Extreme Discontinuity controls
. 
. sort state year
{txt}
{com}. 
. python
{txt}{hline 47} python (type {cmd:end} to exit) {hline}
{com}>>> 
>>> import numpy as np
>>> import pandas as p 
>>> from sfi import Data 
>>> 
>>> 
>>> def getDSCDummies(data, col, cutoff):
... 
...         tempExtState = None
... 
...         tempIndex = 0
...         stateCol = 0
... 
...         rows, cols = data.shape
... 
...         dummyExt = []
... 
...         for i in range(rows):
...                 tempDiff = float(data[i,col])
...                 tempState = data[i,stateCol]
... 
... 
...                 if(abs(tempDiff)>cutoff):
...                         tempExtState = tempState
...                         tempIndex+=1
... 
...                 if tempState==tempExtState:
...                         dummyExt.append(tempIndex)
...                 else:
...                         dummyExt.append(0)
... 
... 
...         dummyExt = np.array(dummyExt).reshape((-1,1))
...         return dummyExt
... 
>>> dataCols = ['state', 'year', 'normDiffLogReg', 'normDiffLogVMT', 'normDiffLogRegPerCapita', 'normDiffLogVMTPerCapita']
>>> 
>>> data = np.array(Data.get(dataCols, missingval=np.nan))
>>> 
>>> print(data)
{res}[['Alabama' '1970' 'nan' 'nan' 'nan' 'nan']
 ['Alabama' '1971' '1.0640671570008131' '0.3361620217656708'
  '0.9150116516585626' '0.16061868662892634']
 ['Alabama' '1972' '1.0231103264075507' '0.24914037544421433'
  '0.9109946118213749' '0.11750494756107976']
 ...
 ['Wyoming' '2016' '0.45763583139776387' '-1.6128834808565655'
  '0.7516965179523265' '-1.1845977355288309']
 ['Wyoming' '2017' '-1.1510098900675998' '0.6274459465980643'
  '-0.8234171123760192' '1.2249676800199891']
 ['Wyoming' '2018' 'nan' 'nan' 'nan' 'nan']]
{com}>>> 
>>> regCutoffLow = 2.93 #Spec. 4
>>> regCutoffPrimary = 4.02 #Spec. 3
>>> regCutoffHigh = 7 #Spec. 2
>>> 
>>> vmtCutoffLow = 2.93 #Spec. 4
>>> vmtCutoffPrimary = 4.02 #Spec. 3
>>> vmtCutoffHigh = 7 #Spec. 2
>>> 
>>> regCol = dataCols.index('normDiffLogReg')
>>> vmtCol = dataCols.index('normDiffLogVMT')
>>> 
>>> regPerCapitaCol = dataCols.index('normDiffLogRegPerCapita')
>>> vmtPerCapitaCol = dataCols.index('normDiffLogVMTPerCapita')
>>> 
>>> rows, cols = data.shape
>>> 
>>> regDummyExtLow = getDSCDummies(data, regCol, regCutoffLow)
>>> regDummyExtPrimary = getDSCDummies(data, regCol, regCutoffPrimary)
>>> regDummyExtHigh = getDSCDummies(data, regCol, regCutoffHigh)
>>> 
>>> vmtDummyExtLow = getDSCDummies(data, vmtCol, vmtCutoffLow)
>>> vmtDummyExtPrimary = getDSCDummies(data, vmtCol, vmtCutoffPrimary)
>>> vmtDummyExtHigh = getDSCDummies(data, vmtCol, vmtCutoffHigh)
>>> 
>>> regPerCapitaDummyExtLow = getDSCDummies(data, regPerCapitaCol, regCutoffLow)
>>> regPerCapitaDummyExtPrimary = getDSCDummies(data, regPerCapitaCol, regCutoffPrimary)
>>> regPerCapitaDummyExtHigh = getDSCDummies(data, regPerCapitaCol, regCutoffHigh)
>>> 
>>> vmtPerCapitaDummyExtLow = getDSCDummies(data, vmtPerCapitaCol, vmtCutoffLow)
>>> vmtPerCapitaDummyExtPrimary = getDSCDummies(data, vmtPerCapitaCol, vmtCutoffPrimary)
>>> vmtPerCapitaDummyExtHigh = getDSCDummies(data, vmtPerCapitaCol, vmtCutoffHigh)
>>> 
>>> Data.addVarInt('regDummyExtSpec4')
>>> Data.store("regDummyExtSpec4",None, regDummyExtLow[:])
>>> Data.addVarInt('regDummyExtSpec3')
>>> Data.store("regDummyExtSpec3",None, regDummyExtPrimary[:])
>>> Data.addVarInt('regDummyExtSpec2')
>>> Data.store("regDummyExtSpec2",None, regDummyExtHigh[:])
>>> 
>>> Data.addVarInt('vmtDummyExtSpec4')
>>> Data.store("vmtDummyExtSpec4",None, vmtDummyExtLow[:])
>>> Data.addVarInt('vmtDummyExtSpec3')
>>> Data.store("vmtDummyExtSpec3",None, vmtDummyExtPrimary[:])
>>> Data.addVarInt('vmtDummyExtSpec2')
>>> Data.store("vmtDummyExtSpec2",None, vmtDummyExtHigh[:])
>>> 
>>> 
>>> Data.addVarInt('regPerCapitaDummyExtSpec4')
>>> Data.store("regPerCapitaDummyExtSpec4",None, regPerCapitaDummyExtLow[:])
>>> Data.addVarInt('regPerCapitaDummyExtSpec3')
>>> Data.store("regPerCapitaDummyExtSpec3",None, regPerCapitaDummyExtPrimary[:])
>>> Data.addVarInt('regPerCapitaDummyExtSpec2')
>>> Data.store("regPerCapitaDummyExtSpec2",None, regPerCapitaDummyExtHigh[:])
>>> 
>>> Data.addVarInt('vmtPerCapitaDummyExtSpec4')
>>> Data.store("vmtPerCapitaDummyExtSpec4",None, vmtPerCapitaDummyExtLow[:])
>>> Data.addVarInt('vmtPerCapitaDummyExtSpec3')
>>> Data.store("vmtPerCapitaDummyExtSpec3",None, vmtPerCapitaDummyExtPrimary[:])
>>> Data.addVarInt('vmtPerCapitaDummyExtSpec2')
>>> Data.store("vmtPerCapitaDummyExtSpec2",None, vmtPerCapitaDummyExtHigh[:])
>>>         
>>> end
{txt}{hline}

{com}. 
. 
. //Generate normalized year values to reduce differences in magnitude of covariates.
. //Scale year for better numerical performance
. local yearScale = 1
{txt}
{com}. gen normYear = year/`yearScale'
{txt}
{com}. gen quadYear = (year/1)^2
{txt}
{com}. 
. //Establish treatment interacted with pre-treatment population share in metro areas
. frame copy default MetroShares
{txt}
{com}. frame change MetroShares
{txt}
{com}. keep if year==1970
{txt}(2,424 observations deleted)

{com}. 
. capture gen preTreatMetroShare = metropopulation/(metropopulation+nonmetropopulation)
{txt}
{com}. 
. frame change default 
{txt}
{com}. 
. cap frlink m:1 state, frame(MetroShares)
{txt}
{com}. cap frget preTreatMetroShare, from(MetroShares)
{txt}
{com}. 
. cap gen metroIntTreatment = nosafetyind*preTreatMetroShare
{txt}
{com}. 
. frame drop MetroShares
{txt}
{com}. 
{txt}end of do-file

{com}. 
. // Urban-Rural models
. capture frame drop ruralUrban
{txt}
{com}. capture drop ruralUrban ruralvmt urbanvmt logruralvmt logurbanvmt
{txt}
{com}. do VMTIVUrbanRural
{txt}
{com}. eststo clear
{txt}
{com}. 
. 
. if("`c(os)'"=="Windows"){c -(}
.         local tableSaveDir = "ReviewResponseResults\"
.         local plotSaveDir = "ReviewResponseResults\"
.         local pythonSaveDir = "PythonScripts\"
. {c )-}
{txt}
{com}. else{c -(}
.         local tableSaveDir = "ReviewResponseResults/"
.         local plotSaveDir = "ReviewResponseResults/"
.         local pythonSaveDir = "PythonScripts/"
. {c )-}
{txt}
{com}. 
. //Establish Control Variable Sets
. //Spec1 controls are the same for both registrations and VMT 
. local spec1Controls = "c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage"
{txt}
{com}. 
. //Other controls are not the same for both registrations and VMT 
. //Registration Controls
. local spec2RegControls = "`spec1Controls' i.transactionDataDummy"
{txt}
{com}. local spec3RegControls = "`spec2RegControls' i.regDummyExtSpec3"
{txt}
{com}. local spec4RegControls = "`spec2RegControls' i.regDummyExtSpec4"
{txt}
{com}. 
. 
. di "`spec3RegControls'"
{res}c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.transactionDataDummy i.regDummyExtSpec3
{txt}
{com}. 
. //VMT Controls
. local spec2VMTControls = "`spec1Controls'"
{txt}
{com}. local spec3VMTControls = "`spec2VMTControls' i.vmtDummyExtSpec3"
{txt}
{com}. local spec4VMTControls = "`spec2VMTControls' i.vmtDummyExtSpec4"
{txt}
{com}. 
. //Absorb Vars are always time and state fixed effects
. local absorbVars = "ib51.stateGroup ib1995.year"
{txt}
{com}. 
. //Establish Cluster Variable
. local clusterVar = "stateGroup year"
{txt}
{com}. 
. //Establish primary null
. local primaryNull = 1.6
{txt}
{com}. local altNull = 1
{txt}
{com}. local altNull2 = 0.3
{txt}
{com}. local altNull3 = 0
{txt}
{com}. local altNull4 = -2.5
{txt}
{com}. 
. frame create ruralUrban
{txt}
{com}. frame change ruralUrban
{txt}
{com}. 
. if("`c(os)'"=="Windows"){c -(}
.         local dataFile = "CleanedData\UrbanRuralVMT.csv"
. {c )-}
{txt}
{com}. else{c -(}
.         local dataFile = "CleanedData/UrbanRuralVMT.csv"
. {c )-}
{txt}
{com}. 
. import delimited using "`dataFile'"
{res}{txt}(encoding automatically selected: ISO-8859-1)
{res}{text}(4 vars, 2,652 obs)

{com}. 
. frame change default
{txt}
{com}. frlink 1:1 year state, frame(ruralUrban)
{res}{txt}  (all observations in frame {bf:default} matched)
{res}{txt}
{com}. frget ruralvmt urbanvmt, from(ruralUrban)
{res}{txt}{p 2 3 2}
(2 variables copied from linked frame)
{p_end}

{com}. gen logruralvmt = log(ruralvmt)
{txt}(47 missing values generated)

{com}. gen logurbanvmt = log(urbanvmt)
{txt}
{com}. 
. bro state year ruralvmt urbanvmt
{txt}
{com}. 
. //Urban model
. //non-normalized models
. local treatmentVar = "1.nosafetyind"
{txt}
{com}. 
. local fsVarsSpec2 = "logregistrations i.nosafetyind `spec2RegControls'"
{txt}
{com}. local rfVarsSpec2 = "logurbanvmt i.nosafetyind `spec2VMTControls'"
{txt}
{com}. local modelTitleSpec2 = "Spec2Urban"
{txt}
{com}. 
. local fsOut = "logregistrations"
{txt}
{com}. local rfOut = "logurbanvmt"
{txt}
{com}. 
. local treatControl = "nosafetyind"
{txt}
{com}. 
. local fsControlsSpec2 = "`spec2RegControls'"
{txt}
{com}. local rfControlsSpec2 = "`spec2VMTControls'"
{txt}
{com}. 
. 
. local nullLowSpec2 = -4
{txt}
{com}. local nullDeltaSpec2 = 0.001
{txt}
{com}. local nullHighSpec2 = 10
{txt}
{com}. 
. // runModel `fsVarsSpec2', `rfVarsSpec2', `clusterVar', `treatmentVar', `modelTitleSpec2', `nullLowSpec2', `nullDeltaSpec2', `nullHighSpec2', `primaryNull', `altNull', `altNull2', `altNull3', `altNull4'
. runModelFWL `fsOut', `rfOut', `fsControlsSpec2', `rfControlsSpec2', `treatControl', `absorbVars', `clusterVar', `treatmentVar', `modelTitleSpec2', `nullLowSpec2', `nullDeltaSpec2', `nullHighSpec2', `primaryNull', `altNull', `altNull2', `altNull3', `altNull4'
logregistrations
logurbanvmt
c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.transactionDataDummy
c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage
nosafetyind
ib51.stateGroup ib1995.year
Working on:Spec2Urban

{txt}      Source {c |}       SS           df       MS      Number of obs   ={res}     2,424
{txt}{hline 13}{c +}{hline 34}   F(1, 2423)      = {res}    32.78
{txt}       Model {c |} {res} .075299639         1  .075299639   {txt}Prob > F        ={res}    0.0000
{txt}    Residual {c |} {res} 5.56653287     2,423  .002297372   {txt}R-squared       ={res}    0.0133
{txt}{hline 13}{c +}{hline 34}   Adj R-squared   ={res}    0.0129
{txt}       Total {c |} {res} 5.64183251     2,424  .002327489   {txt}Root MSE        =   {res} .04793

{txt}{hline 19}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}logregistrations~s{col 20}{c |} Coefficient{col 32}  Std. err.{col 44}      t{col 52}   P>|t|{col 60}     [95% con{col 73}f. interval]
{hline 19}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
fs_nosafetyind_res {c |}{col 20}{res}{space 2} .0525274{col 32}{space 2}  .009175{col 43}{space 1}    5.73{col 52}{space 3}0.000{col 60}{space 4} .0345358{col 73}{space 3}  .070519
{txt}{hline 19}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}Current approach can handle two-way clustering. Higher dimensional clustering will produce incorrect results.

{txt}scalars:
              r(covar) =  {res}.0001219344201541
           {txt}r(covarLow) =  {res}.0001219344201541
          {txt}r(covarHigh) =  {res}.0001229438990137
           {txt}r(deltaVar) =  {res}.0009336235884885
              {txt}r(piVar) =  {res}.0002269831190162
   {txt}r(covarUncorrected) =  {res}.0001140231089826
  {txt}r(deltaVarUncorrect
    ed)                =  {res}.0008658800073283
   {txt}r(piVarUncorrected) =  {res}.0002105132594982
              {txt}r(delta) =  {res}.0027361678085669
                 {txt}r(pi) =  {res}.0525273813782378
       {txt}r(rfCorrection) =  {res}1.069383401680796
       {txt}r(fsCorrection) =  {res}1.07823668474482
                  {txt}r(N) =  {res}2424
             {txt}r(nClust) =  {res}48
            {txt}r(nClust2) =  {res}48
            {txt}r(nClust1) =  {res}51
  {txt}r(covarUncorrectedR) =  {res}1.00501914046e-06
  {txt}r(deltaVarUncorrect
    edR)               =  {res}.0001493706983705
  {txt}r(piVarUncorrectedR) =  {res}.000091730792029
  {txt}r(covarUncorrected2) =  {res}-.0000130052746697
  {txt}r(deltaVarUncorrect
    ed2)               =  {res}.0000993048009664
  {txt}r(piVarUncorrected2) =  {res}.0001238976598154
  {txt}r(covarUncorrected1) =  {res}.0001280334027928
  {txt}r(deltaVarUncorrect
    ed1)               =  {res}.0009159459047324
  {txt}r(piVarUncorrected1) =  {res}.0001783463917119
                {txt}r(rfK) =  {res}110
                {txt}r(fsK) =  {res}129
{txt}
{com}. 
. //Rural model
. preserve
{txt}
{com}. drop if state=="Dist. of Col."
{txt}(49 observations deleted)

{com}. 
. local fsVarsSpec2 = "logregistrations i.nosafetyind `spec2RegControls'"
{txt}
{com}. local rfVarsSpec2 = "logruralvmt i.nosafetyind `spec2VMTControls'"
{txt}
{com}. 
. local rfOut = "logruralvmt"
{txt}
{com}. 
. local modelTitleSpec2 = "Spec2Rural"
{txt}
{com}. local nullLowSpec2 = -10
{txt}
{com}. local nullDeltaSpec2 = .01
{txt}
{com}. local nullHighSpec2 = 50
{txt}
{com}. 
. runModelFWL `fsOut', `rfOut', `fsControlsSpec2', `rfControlsSpec2', `treatControl', `absorbVars', `clusterVar', `treatmentVar', `modelTitleSpec2', `nullLowSpec2', `nullDeltaSpec2', `nullHighSpec2', `primaryNull', `altNull', `altNull2', `altNull3', `altNull4'
logregistrations
logruralvmt
c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.transactionDataDummy
c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage
nosafetyind
ib51.stateGroup ib1995.year
Working on:Spec2Rural

{txt}      Source {c |}       SS           df       MS      Number of obs   ={res}     2,376
{txt}{hline 13}{c +}{hline 34}   F(1, 2375)      = {res}    25.78
{txt}       Model {c |} {res}  .05554681         1   .05554681   {txt}Prob > F        ={res}    0.0000
{txt}    Residual {c |} {res} 5.11743543     2,375   .00215471   {txt}R-squared       ={res}    0.0107
{txt}{hline 13}{c +}{hline 34}   Adj R-squared   ={res}    0.0103
{txt}       Total {c |} {res} 5.17298224     2,376  .002177181   {txt}Root MSE        =   {res} .04642

{txt}{hline 19}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}logregistrations~s{col 20}{c |} Coefficient{col 32}  Std. err.{col 44}      t{col 52}   P>|t|{col 60}     [95% con{col 73}f. interval]
{hline 19}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
fs_nosafetyind_res {c |}{col 20}{res}{space 2} .0464165{col 32}{space 2} .0091419{col 43}{space 1}    5.08{col 52}{space 3}0.000{col 60}{space 4} .0284896{col 73}{space 3} .0643435
{txt}{hline 19}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}Current approach can handle two-way clustering. Higher dimensional clustering will produce incorrect results.

{txt}scalars:
              r(covar) =  {res}-.0000615467961005
           {txt}r(covarLow) =  {res}-.0000615467961005
          {txt}r(covarHigh) =  {res}-.0000610311924295
           {txt}r(deltaVar) =  {res}.0005327078416854
              {txt}r(piVar) =  {res}.0002212379564952
   {txt}r(covarUncorrected) =  {res}-.0000570673770896
  {txt}r(deltaVarUncorrect
    ed)                =  {res}.0004939369911375
   {txt}r(piVarUncorrected) =  {res}.0002051361027668
              {txt}r(delta) =  {res}-.0166833548444636
                 {txt}r(pi) =  {res}.0464165245441927
       {txt}r(rfCorrection) =  {res}1.069458516267027
       {txt}r(fsCorrection) =  {res}1.078493514848207
                  {txt}r(N) =  {res}2376
             {txt}r(nClust) =  {res}48
            {txt}r(nClust2) =  {res}48
            {txt}r(nClust1) =  {res}50
  {txt}r(covarUncorrectedR) =  {res}-3.08434864634e-06
  {txt}r(deltaVarUncorrect
    edR)               =  {res}.0001403832056664
  {txt}r(piVarUncorrectedR) =  {res}.0000545168957183
  {txt}r(covarUncorrected2) =  {res}-3.50445381332e-06
  {txt}r(deltaVarUncorrect
    ed2)               =  {res}.0001358120130671
  {txt}r(piVarUncorrected2) =  {res}.0000632642110365
  {txt}r(covarUncorrected1) =  {res}-.0000566472719226
  {txt}r(deltaVarUncorrect
    ed1)               =  {res}.0004985081837368
  {txt}r(piVarUncorrected1) =  {res}.0001963887874486
                {txt}r(rfK) =  {res}108
                {txt}r(fsK) =  {res}127
{txt}
{com}. // runModel `fsVarsSpec2', `rfVarsSpec2', `clusterVar', `treatmentVar', `modelTitleSpec2', `nullLowSpec2', `nullDeltaSpec2', `nullHighSpec2', `primaryNull', `altNull', `altNull2', `altNull3', `altNull4'
. 
. restore
{txt}
{com}. 
. // python script "`pythonSaveDir'combineIV.py" 
. //
. //
. // constructTable VMTPerCapitaiv; Fleet Travel Distance Per Capita; Spec1PerCapita Spec2PerCapita Spec3PerCapita Spec4PerCapita; `primaryNull'; `altNull'; `altNull2'; `altNull3'; `altNull4'
. // constructTable VMTiv; Fleet Travel Distance ; Spec1 Spec2 Spec3 Spec4; `primaryNull'; `altNull'; `altNull2'; `altNull3'; `altNull4'
. 
{txt}end of do-file

{com}. 
. //Interacted treatment with metro population share
. do RegDiDMetro
{txt}
{com}. eststo clear
{txt}
{com}. 
. if("`c(os)'"=="Windows"){c -(}
.         local tableSaveDir = "Tables\DiD\"
.         local plotSaveDir = "Plots\"
.         local pythonSaveDir = "PythonScripts\"
. {c )-}
{txt}
{com}. else{c -(}
.         local tableSaveDir = "Tables/DiD/"
.         local plotSaveDir = "Plots/"
.         local pythonSaveDir = "PythonScripts/"
. {c )-}
{txt}
{com}. 
. //With linear and quadratic time trends
. //Establish Control Variable Sets
. local spec1Controls = "c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage"
{txt}
{com}. local spec2Controls = "`spec1Controls' i.transactionDataDummy"
{txt}
{com}. local spec3Controls = "`spec2Controls' i.regDummyExtSpec3"
{txt}
{com}. local spec4Controls = "`spec2Controls' i.regDummyExtSpec4"
{txt}
{com}. 
. //Establish ci level
. local ciLevel = 95
{txt}
{com}. 
. //Establish Cluster Variable
. local clusterVar = "stateGroup year"
{txt}
{com}. 
. //Absorb Vars are always time and state fixed effects
. local absorbVars = "ib51.stateGroup ib1995.year"
{txt}
{com}. 
. //Estimate Models
. //Estimate Primary Spec. 2 DiD Models
. regFWL logregistrations, nosafetyind, `spec2Controls', `absorbVars', `clusterVar', _
absorb: ib51.stateGroup ib1995.year

{txt}scalars:
                  e(N) =  {res}2424
               {txt}e(df_m) =  {res}1
               {txt}e(df_r) =  {res}2423
                  {txt}e(F) =  {res}32.77642113692301
                 {txt}e(r2) =  {res}.0133466633423204
               {txt}e(rmse) =  {res}.0479309108348405
                {txt}e(mss) =  {res}.0752996391765457
                {txt}e(rss) =  {res}5.566532873207353
               {txt}e(r2_a) =  {res}.0129394601493127
                 {txt}e(ll) =  {res}3925.09216070153
               {txt}e(rank) =  {res}1

{txt}macros:
            e(cmdline) : "{res}regress logregistrations_res  nosafetyind_res, nocon{txt}"
              e(title) : "{res}Linear regression{txt}"
          e(marginsok) : "{res}XB default{txt}"
                e(vce) : "{res}ols{txt}"
             e(depvar) : "{res}logregistrations_res{txt}"
                e(cmd) : "{res}regress{txt}"
         e(properties) : "{res}b V{txt}"
            e(predict) : "{res}regres_p{txt}"
              e(model) : "{res}ols{txt}"
          e(estat_cmd) : "{res}regress_estat{txt}"

matrices:
                  e(b) : {res} 1 x 1
                  {txt}e(V) : {res} 1 x 1
               {txt}e(beta) : {res} 1 x 1

{txt}functions:
             e(sample)   
{res}
{txt}{space 0}{space 13}{c |}{res}{txt}{space 1}{lalign 9:mean}{space 1}{c |}{res}{txt}{space 1}{lalign 9:lnvar}{space 1}
{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:nosafet~s}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:mean}}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:nosafetyin~s}{space 1}{c |}{space 1}{ralign 9:{res:{sf:  .000227}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:lnvar}}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:_cons}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0006376}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0169832}}}{space 1}

{com}. matlist e(b)
{res}
{txt}{space 0}{space 13}{c |}{res}{txt}{space 1}{lalign 9:mean}{space 1}{c |}{res}{txt}{space 1}{lalign 9:lnvar}{space 1}
{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:nosafet~s}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{space 0}{ralign 12:y1}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0525274}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:-6.075989}}}{space 1}

{com}. matlist e(V)
{res}
{txt}{space 0}{space 13}{c |}{res}{txt}{space 1}{lalign 9:mean}{space 1}{c |}{res}{txt}{space 1}{lalign 9:lnvar}{space 1}
{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:nosafet~s}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:mean}}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:nosafetyin~s}{space 1}{c |}{space 1}{ralign 9:{res:{sf:  .000227}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:lnvar}}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:_cons}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0006376}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0169832}}}{space 1}

{com}. //Estimate Alternative Spec. 2 DiD Model 
. regFWL logregistrations, nosafetyind metroIntTreatment, `spec2Controls', `absorbVars', `clusterVar', _
absorb: ib51.stateGroup ib1995.year

{txt}scalars:
                  e(N) =  {res}2424
               {txt}e(df_m) =  {res}2
               {txt}e(df_r) =  {res}2422
                  {txt}e(F) =  {res}18.63824523175877
                 {txt}e(r2) =  {res}.0151575028704852
               {txt}e(rmse) =  {res}.0478967907910025
                {txt}e(mss) =  {res}.0855160925012557
                {txt}e(rss) =  {res}5.556316419882643
               {txt}e(r2_a) =  {res}.014344255556588
                 {txt}e(ll) =  {res}3927.318630661779
               {txt}e(rank) =  {res}2

{txt}macros:
            e(cmdline) : "{res}regress logregistrations_res  nosafetyind_res metroIntTreatment_res, nocon{txt}"
              e(title) : "{res}Linear regression{txt}"
          e(marginsok) : "{res}XB default{txt}"
                e(vce) : "{res}ols{txt}"
             e(depvar) : "{res}logregistrations_res{txt}"
                e(cmd) : "{res}regress{txt}"
         e(properties) : "{res}b V{txt}"
            e(predict) : "{res}regres_p{txt}"
              e(model) : "{res}ols{txt}"
          e(estat_cmd) : "{res}regress_estat{txt}"

matrices:
                  e(b) : {res} 1 x 2
                  {txt}e(V) : {res} 2 x 2
               {txt}e(beta) : {res} 1 x 2

{txt}functions:
             e(sample)   
{res}
{txt}{space 0}{space 13}{c |}{res}{txt}{space 1}{lalign 9:mean}{space 1}{space 11}{c |}{res}{txt}{space 1}{lalign 9:lnvar}{space 1}
{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:nosafet~s}{space 1}{space 1}{ralign 9:metroIn~s}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:mean}}{c |}{space 11}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:nosafetyin~s}{space 1}{c |}{space 1}{ralign 9:{res:{sf:  .002443}}}{space 1}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{space 0}{ralign 12:metroIntTr~s}{space 1}{c |}{space 1}{ralign 9:{res:{sf:-.0036377}}}{space 1}{space 1}{ralign 9:{res:{sf: .0059349}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:lnvar}}{c |}{space 11}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:_cons}{space 1}{c |}{space 1}{ralign 9:{res:{sf:-.0013726}}}{space 1}{space 1}{ralign 9:{res:{sf: .0027701}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:  .016772}}}{space 1}

{com}. matlist e(b)
{res}
{txt}{space 0}{space 13}{c |}{res}{txt}{space 1}{lalign 9:mean}{space 1}{space 11}{c |}{res}{txt}{space 1}{lalign 9:lnvar}{space 1}
{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:nosafet~s}{space 1}{space 1}{ralign 9:metroIn~s}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{hline 11}{c   +}{hline 11}
{space 0}{space 0}{ralign 12:y1}{space 1}{c |}{space 1}{ralign 9:{res:{sf:-.0077175}}}{space 1}{space 1}{ralign 9:{res:{sf: .0917635}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:-6.077414}}}{space 1}

{com}. matlist e(V)
{res}
{txt}{space 0}{space 13}{c |}{res}{txt}{space 1}{lalign 9:mean}{space 1}{space 11}{c |}{res}{txt}{space 1}{lalign 9:lnvar}{space 1}
{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:nosafet~s}{space 1}{space 1}{ralign 9:metroIn~s}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:mean}}{c |}{space 11}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:nosafetyin~s}{space 1}{c |}{space 1}{ralign 9:{res:{sf:  .002443}}}{space 1}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{space 0}{ralign 12:metroIntTr~s}{space 1}{c |}{space 1}{ralign 9:{res:{sf:-.0036377}}}{space 1}{space 1}{ralign 9:{res:{sf: .0059349}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:lnvar}}{c |}{space 11}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:_cons}{space 1}{c |}{space 1}{ralign 9:{res:{sf:-.0013726}}}{space 1}{space 1}{ralign 9:{res:{sf: .0027701}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:  .016772}}}{space 1}

{com}. eststo spec2
{txt}
{com}. local df = e(N_clust)-1
{txt}
{com}. addRobustFStat "mean:nosafetyind_res"

{txt}added scalar:
              e(fStat) =  {res}.0243793
{txt}
{com}. addTreat "mean:nosafetyind_res"
hello
5
mean
nosafetyind_res

{p 0 7}{space 1}{text:( 1)}{space 1} {res}[mean]nosafetyind_res = 0{p_end}

{txt}{col 12}chi2(  1) ={res}    0.02
{txt}{col 10}Prob > chi2 =  {res}  0.8759
hello2

{txt}added macro:
             e(treatb) : "{res:0-.008}"

{com}. 
. test [mean]nosafetyind_res

{p 0 7}{space 1}{text:( 1)}{space 1} {res}[mean]nosafetyind_res = 0{p_end}

{txt}{col 12}chi2(  1) ={res}    0.02
{txt}{col 10}Prob > chi2 =  {res}  0.8759
{txt}
{com}. test [mean]metroIntTreatment_res

{p 0 7}{space 1}{text:( 1)}{space 1} {res}[mean]metroIntTreatment_res = 0{p_end}

{txt}{col 12}chi2(  1) ={res}    1.42
{txt}{col 10}Prob > chi2 =  {res}  0.2336
{txt}
{com}. 
. estadd local dsc = "Documented" 

{txt}added macro:
                e(dsc) : "{res:Documented}"

{com}. estadd local groupFE = "Y"

{txt}added macro:
            e(groupFE) : "{res:Y}"

{com}. estadd local timeFE = "Y"

{txt}added macro:
             e(timeFE) : "{res:Y}"

{com}. estadd local timeTrend = "Y"

{txt}added macro:
          e(timeTrend) : "{res:Y}"

{com}. estadd local quadTrend = "Y"

{txt}added macro:
          e(quadTrend) : "{res:Y}"

{com}. estadd local commonControls = "Y"

{txt}added macro:
     e(commonControls) : "{res:Y}"

{com}. estadd local modelNum = "(2)"

{txt}added macro:
           e(modelNum) : "{res:(2)}"

{com}. 
. 
. //Export Model Results to TeX Files
. //Establish Format
. local fmtDiD = `"drop(*) nocon label compress starlevels(* 0.1 ** 0.05 *** 0.01) nodepvar nomtitle nonumbers not nostar noline"'
{txt}
{com}. 
. 
. // local noteString = "\hline \hline \end{c -(}tabular{c )-} \vspace{c -(}0.2cm{c )-} \begin{c -(}tablenotes{c )-} \begin{c -(}spacing{c )-}{c -(}0{c )-} \begin{c -(}footnotesize{c )-} \item \textbf{c -(}Notes:{c )-} This table presents difference-in-differences estimates of the impact of the removal of safety inspections on the log of vehicle registrations.  The unit of observation is state-year. The four specifications pertaining to different levels of ``Data Source Controls'' (DSCs) and control specifications are documented in Table \cref{c -(}ssec:Spec{c )-}. Standard errors, reported in parentheses, are clustered by state. * p\textless 0.1, ** p\textless 0.05, *** p\textless 0.01 \end{c -(}footnotesize{c )-} \end{c -(}spacing{c )-} \end{c -(}tablenotes{c )-} \end{c -(}table{c )-}"
. //
. // //Export Table
. // esttab spec1 spec2 spec3 spec4 using "`tableSaveDir'RegDiD.tex", `fmtDiD' title("Diff-in-Diff Results \label{c -(}tab:RegDiD{c )-}") stats(modelNum treatb treatse dsc groupFE timeFE timeTrend quadTrend commonControls fStat N r2, labels("\hline \hline \multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}Dep. Var.: Log Number of Vehicle Registrations{c )-} \\ " "Removal of" "Safety Inspections" "\makecell[l]{c -(}Data Source \nextline Controls{c )-}" "State Fixed Effects" "Year Fixed Effects" "\makecell[l]{c -(}State-Specific Linear \\ Time Trends{c )-}" "\makecell[l]{c -(}State-Specific Quadratic \\ Time Trends{c )-}" "Common Controls" "Robust F-Stat" "Number of Obs." "R\textsuperscript{c -(}2{c )-}")fmt(%8.3f %8.3f %8.3f %8.3f  %8.3f  %8.3f  %8.3f  %8.3f %8.3f %8.0fc %8.3f)) replace postfoot("`noteString'")
. 
{txt}end of do-file

{com}. 
. // Urban-Rural Reduced Form Comparison
. capture frame drop ruralUrban
{txt}
{com}. capture drop ruralUrban ruralvmt urbanvmt logruralvmt logurbanvmt
{txt}
{com}. do VMTRFRuralUrban
{txt}
{com}. eststo clear
{txt}
{com}. 
. 
. if("`c(os)'"=="Windows"){c -(}
.         local tableSaveDir = "ReviewResponseResults\"
.         local plotSaveDir = "ReviewResponseResults\"
.         local pythonSaveDir = "PythonScripts\"
. {c )-}
{txt}
{com}. else{c -(}
.         local tableSaveDir = "ReviewResponseResults/"
.         local plotSaveDir = "ReviewResponseResults/"
.         local pythonSaveDir = "PythonScripts/"
. {c )-}
{txt}
{com}. 
. //Establish Control Variable Sets
. //Spec1 controls are the same for both registrations and VMT 
. local spec1Controls = "c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage"
{txt}
{com}. 
. //Other controls are not the same for both registrations and VMT 
. //Registration Controls
. local spec2RegControls = "`spec1Controls' i.transactionDataDummy"
{txt}
{com}. local spec3RegControls = "`spec2RegControls' i.regDummyExtSpec3"
{txt}
{com}. local spec4RegControls = "`spec2RegControls' i.regDummyExtSpec4"
{txt}
{com}. 
. 
. di "`spec3RegControls'"
{res}c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.transactionDataDummy i.regDummyExtSpec3
{txt}
{com}. 
. //VMT Controls
. local spec2VMTControls = "`spec1Controls'"
{txt}
{com}. local spec3VMTControls = "`spec2VMTControls' i.vmtDummyExtSpec3"
{txt}
{com}. local spec4VMTControls = "`spec2VMTControls' i.vmtDummyExtSpec4"
{txt}
{com}. 
. //Absorb Vars are always time and state fixed effects
. local absorbVars = "ib51.stateGroup ib1995.year"
{txt}
{com}. 
. //Establish Cluster Variable
. local clusterVar = "stateGroup year"
{txt}
{com}. 
. //Establish primary null
. local primaryNull = 1.6
{txt}
{com}. local altNull = 1
{txt}
{com}. local altNull2 = 0.3
{txt}
{com}. local altNull3 = 0
{txt}
{com}. local altNull4 = -2.5
{txt}
{com}. 
. frame create ruralUrban
{txt}
{com}. frame change ruralUrban
{txt}
{com}. 
. if("`c(os)'"=="Windows"){c -(}
.         local dataFile = "CleanedData\UrbanRuralVMT.csv"
. {c )-}
{txt}
{com}. else{c -(}
.         local dataFile = "CleanedData/UrbanRuralVMT.csv"
. {c )-}
{txt}
{com}. 
. import delimited using "`dataFile'"
{res}{txt}(encoding automatically selected: ISO-8859-1)
{res}{text}(4 vars, 2,652 obs)

{com}. 
. frame change default
{txt}
{com}. frlink 1:1 year state, frame(ruralUrban)
{res}{txt}  (all observations in frame {bf:default} matched)
{res}{txt}
{com}. frget ruralvmt urbanvmt, from(ruralUrban)
{res}{txt}{p 2 3 2}
(2 variables copied from linked frame)
{p_end}

{com}. gen logruralvmt = log(ruralvmt)
{txt}(47 missing values generated)

{com}. gen logurbanvmt = log(urbanvmt)
{txt}
{com}. 
. 
. //Run urban model to get appropriate N and K values.
. qui reghdfe logurbanvmt nosafetyind `spec2VMTControls', absorb(`absorbVars') cluster(`clusterVar')
{txt}
{com}. local k_u = e(df_a)+e(df_m)
{txt}
{com}. local N_u = e(N)
{txt}
{com}. local r2_u = e(r2)
{txt}
{com}. local N_clust_u = e(N_clust)
{txt}
{com}. local correction_u = (`N_clust_u')/(`N_clust_u'-1)*(`N_u'-1)/(`N_u'-`k_u')
{txt}
{com}. 
. //Run rural model to get appropriate N and K values.
. qui reghdfe logruralvmt nosafetyind `spec2VMTControls' if state!="Dist. of Col.", absorb(`absorbVars') cluster(`clusterVar')
{txt}
{com}. local k_r = e(df_a)+e(df_m)
{txt}
{com}. local N_r = e(N)
{txt}
{com}. local r2_r = e(r2)
{txt}
{com}. local N_clust_r = e(N_clust)
{txt}
{com}. local correction_r = (`N_clust_r')/(`N_clust_r'-1)*(`N_r'-1)/(`N_r'-`k_r')
{txt}
{com}. 
. //Partial urban model variables
. qui reghdfe logurbanvmt `spec2VMTControls', absorb(`absorbVars') cluster(`clusterVar') res(logurbanvmt_res)
{txt}
{com}. qui reghdfe nosafetyind `spec2VMTControls', absorb(`absorbVars') cluster(`clusterVar') res(nosafetyind_res_u)
{txt}
{com}. 
. //Partial urban model variables
. qui reghdfe logruralvmt `spec2VMTControls' if state!="Dist. of Col.", absorb(`absorbVars') cluster(`clusterVar') res(logruralvmt_res)
{txt}
{com}. qui reghdfe nosafetyind `spec2VMTControls' if state!="Dist. of Col.", absorb(`absorbVars') cluster(`clusterVar') res(nosafetyind_res_r)
{txt}
{com}. 
. //Estimate partialled urban model
. regress logurbanvmt_res nosafetyind_res_u, nocon

{txt}      Source {c |}       SS           df       MS      Number of obs   ={res}     2,424
{txt}{hline 13}{c +}{hline 34}   F(1, 2423)      = {res}     0.04
{txt}       Model {c |} {res} .000219706         1  .000219706   {txt}Prob > F        ={res}    0.8447
{txt}    Residual {c |} {res} 13.8769148     2,423  .005727163   {txt}R-squared       ={res}    0.0000
{txt}{hline 13}{c +}{hline 34}   Adj R-squared   ={res}   -0.0004
{txt}       Total {c |} {res} 13.8771345     2,424   .00572489   {txt}Root MSE        =   {res} .07568

{txt}{hline 18}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}  logurbanvmt_res{col 19}{c |} Coefficient{col 31}  Std. err.{col 43}      t{col 51}   P>|t|{col 59}     [95% con{col 72}f. interval]
{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
nosafetyind_res_u {c |}{col 19}{res}{space 2} .0027362{col 31}{space 2} .0139698{col 42}{space 1}    0.20{col 51}{space 3}0.845{col 59}{space 4}-.0246579{col 72}{space 3} .0301302
{txt}{hline 18}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}{txt}
{com}. estimates store urban
{txt}
{com}. 
. //Estimate partialled rural model 
. regress logruralvmt_res nosafetyind_res_r if state!="Dist. of Col.", nocon

{txt}      Source {c |}       SS           df       MS      Number of obs   ={res}     2,376
{txt}{hline 13}{c +}{hline 34}   F(1, 2375)      = {res}     1.46
{txt}       Model {c |} {res} .007729717         1  .007729717   {txt}Prob > F        ={res}    0.2276
{txt}    Residual {c |} {res} 12.6026585     2,375  .005306383   {txt}R-squared       ={res}    0.0006
{txt}{hline 13}{c +}{hline 34}   Adj R-squared   ={res}    0.0002
{txt}       Total {c |} {res} 12.6103882     2,376  .005307402   {txt}Root MSE        =   {res} .07284

{txt}{hline 18}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}  logruralvmt_res{col 19}{c |} Coefficient{col 31}  Std. err.{col 43}      t{col 51}   P>|t|{col 59}     [95% con{col 72}f. interval]
{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
nosafetyind_res_r {c |}{col 19}{res}{space 2}-.0166834{col 31}{space 2}  .013823{col 42}{space 1}   -1.21{col 51}{space 3}0.228{col 59}{space 4}-.0437897{col 72}{space 3}  .010423
{txt}{hline 18}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}{txt}
{com}. estimates store rural
{txt}
{com}. 
. suest urban rural, vce(cluster stateGroup)
{res}
{txt}{col 1}Simultaneous results for {stata estimates replay urban:urban}, {stata estimates replay rural:rural}{col 58}{lalign 13:Number of obs}{col 71} = {res}{ralign 5:2,424}

{txt}{ralign 83:(Std. err. adjusted for {res:51} clusters in {res:stateGroup})}
{hline 18}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 19}{c |}{col 31}    Robust
{col 19}{c |} Coefficient{col 31}  std. err.{col 43}      z{col 51}   P>|z|{col 59}     [95% con{col 72}f. interval]
{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}urban_mean        {txt}{c |}
nosafetyind_res_u {c |}{col 19}{res}{space 2} .0027362{col 31}{space 2} .0302646{col 42}{space 1}    0.09{col 51}{space 3}0.928{col 59}{space 4}-.0565814{col 72}{space 3} .0620537
{txt}{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}urban_lnvar       {txt}{c |}
{space 12}_cons {c |}{col 19}{res}{space 2}-5.162535{col 31}{space 2} .3934673{col 42}{space 1}  -13.12{col 51}{space 3}0.000{col 59}{space 4}-5.933717{col 72}{space 3}-4.391353
{txt}{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}rural_mean        {txt}{c |}
nosafetyind_res_r {c |}{col 19}{res}{space 2}-.0166834{col 31}{space 2} .0223228{col 42}{space 1}   -0.75{col 51}{space 3}0.455{col 59}{space 4}-.0604353{col 72}{space 3} .0270686
{txt}{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}rural_lnvar       {txt}{c |}
{space 12}_cons {c |}{col 19}{res}{space 2}-5.238845{col 31}{space 2} .2100234{col 42}{space 1}  -24.94{col 51}{space 3}0.000{col 59}{space 4}-5.650483{col 72}{space 3}-4.827207
{txt}{hline 18}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}

{com}. mat var1 = e(V)
{txt}
{com}. suest urban rural, vce(cluster year)
{res}
{txt}{col 1}Simultaneous results for {stata estimates replay urban:urban}, {stata estimates replay rural:rural}{col 58}{lalign 13:Number of obs}{col 71} = {res}{ralign 5:2,424}

{txt}{ralign 83:(Std. err. adjusted for {res:48} clusters in {res:year})}
{hline 18}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 19}{c |}{col 31}    Robust
{col 19}{c |} Coefficient{col 31}  std. err.{col 43}      z{col 51}   P>|z|{col 59}     [95% con{col 72}f. interval]
{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}urban_mean        {txt}{c |}
nosafetyind_res_u {c |}{col 19}{res}{space 2} .0027362{col 31}{space 2} .0099652{col 42}{space 1}    0.27{col 51}{space 3}0.784{col 59}{space 4}-.0167952{col 72}{space 3} .0222676
{txt}{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}urban_lnvar       {txt}{c |}
{space 12}_cons {c |}{col 19}{res}{space 2}-5.162535{col 31}{space 2}  .133141{col 42}{space 1}  -38.77{col 51}{space 3}0.000{col 59}{space 4}-5.423487{col 72}{space 3}-4.901584
{txt}{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}rural_mean        {txt}{c |}
nosafetyind_res_r {c |}{col 19}{res}{space 2}-.0166834{col 31}{space 2} .0116538{col 42}{space 1}   -1.43{col 51}{space 3}0.152{col 59}{space 4}-.0395245{col 72}{space 3} .0061578
{txt}{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}rural_lnvar       {txt}{c |}
{space 12}_cons {c |}{col 19}{res}{space 2}-5.238845{col 31}{space 2} .1074508{col 42}{space 1}  -48.76{col 51}{space 3}0.000{col 59}{space 4}-5.449445{col 72}{space 3}-5.028245
{txt}{hline 18}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}

{com}. mat var2 = e(V)
{txt}
{com}. suest urban rural, vce(robust)
{res}
{txt}{col 1}Simultaneous results for {stata estimates replay urban:urban}, {stata estimates replay rural:rural}{col 58}{lalign 13:Number of obs}{col 71} = {res}{ralign 5:2,424}

{txt}{hline 18}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 19}{c |}{col 31}    Robust
{col 19}{c |} Coefficient{col 31}  std. err.{col 43}      z{col 51}   P>|z|{col 59}     [95% con{col 72}f. interval]
{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}urban_mean        {txt}{c |}
nosafetyind_res_u {c |}{col 19}{res}{space 2} .0027362{col 31}{space 2} .0122217{col 42}{space 1}    0.22{col 51}{space 3}0.823{col 59}{space 4} -.021218{col 72}{space 3} .0266903
{txt}{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}urban_lnvar       {txt}{c |}
{space 12}_cons {c |}{col 19}{res}{space 2}-5.162535{col 31}{space 2} .1099934{col 42}{space 1}  -46.93{col 51}{space 3}0.000{col 59}{space 4}-5.378118{col 72}{space 3}-4.946952
{txt}{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}rural_mean        {txt}{c |}
nosafetyind_res_r {c |}{col 19}{res}{space 2}-.0166834{col 31}{space 2} .0118483{col 42}{space 1}   -1.41{col 51}{space 3}0.159{col 59}{space 4}-.0399056{col 72}{space 3} .0065389
{txt}{hline 18}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}rural_lnvar       {txt}{c |}
{space 12}_cons {c |}{col 19}{res}{space 2}-5.238845{col 31}{space 2} .0789903{col 42}{space 1}  -66.32{col 51}{space 3}0.000{col 59}{space 4}-5.393663{col 72}{space 3}-5.084027
{txt}{hline 18}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}

{com}. mat mat_beta = e(b)
{txt}
{com}. mat varR = e(V)
{txt}
{com}. 
. mat mat_var = var1+var2-varR
{txt}
{com}. 
. matlist mat_beta
{res}
{txt}{space 0}{space 13}{c |}{res}{txt}{space 1}{lalign 9:urban_m~n}{space 1}{c |}{res}{txt}{space 1}{lalign 9:urban_l~r}{space 1}{c |}{res}{txt}{space 1}{lalign 9:rural_m~n}{space 1}{c |}{res}{txt}{space 1}{lalign 9:rural_l~r}{space 1}
{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:nosafet~u}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}{c |}{space 1}{ralign 9:nosafet~r}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{space 0}{ralign 12:y1}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0027362}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:-5.162535}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:-.0166834}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:-5.238845}}}{space 1}

{com}. matlist mat_var
{res}
{txt}{space 0}{space 13}{c |}{res}{txt}{space 1}{lalign 9:urban_m~n}{space 1}{c |}{res}{txt}{space 1}{lalign 9:urban_l~r}{space 1}{c |}{res}{txt}{space 1}{lalign 9:rural_m~n}{space 1}{c |}{res}{txt}{space 1}{lalign 9:rural_l~r}{space 1}
{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:nosafet~u}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}{c |}{space 1}{ralign 9:nosafet~r}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:urban_mean}}{c |}{space 11}{c |}{space 11}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:nosafetyin~u}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0008659}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:urban_lnvar}}{c |}{space 11}{c |}{space 11}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:_cons}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0037833}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .1604445}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:rural_mean}}{c |}{space 11}{c |}{space 11}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:nosafetyin~r}{space 1}{c |}{space 1}{ralign 9:{res:{sf:-.0000512}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0023294}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0004937}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:rural_lnvar}}{c |}{space 11}{c |}{space 11}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:_cons}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0015294}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0574946}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0006068}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0494161}}}{space 1}

{com}. 
. mat diff_r = [1, 0, -1, 0]
{txt}
{com}. matlist diff_r
{res}
{txt}{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:c1}{space 1}{space 1}{ralign 9:c2}{space 1}{space 1}{ralign 9:c3}{space 1}{space 1}{ralign 9:c4}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{hline 11}{hline 11}{hline 11}
{space 0}{space 0}{ralign 12:r1}{space 1}{c |}{space 1}{ralign 9:{res:{sf:        1}}}{space 1}{space 1}{ralign 9:{res:{sf:        0}}}{space 1}{space 1}{ralign 9:{res:{sf:       -1}}}{space 1}{space 1}{ralign 9:{res:{sf:        0}}}{space 1}

{com}. 
. mat diff_value = diff_r*(mat_beta')
{txt}
{com}. matlist diff_value
{res}
{txt}{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:y1}{space 1}
{space 0}{hline 13}{c   +}{hline 11}
{space 0}{space 0}{ralign 12:r1}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0194195}}}{space 1}

{com}. 
. mat diff_var = diff_r*mat_var*(diff_r')
{txt}
{com}. matlist diff_var
{res}
{txt}{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:r1}{space 1}
{space 0}{hline 13}{c   +}{hline 11}
{space 0}{space 0}{ralign 12:r1}{space 1}{c |}{space 1}{ralign 9:{res:{sf:  .001462}}}{space 1}

{com}. 
. local chi_stat = (diff_value[1,1]^2)/sqrt(diff_var[1,1])
{txt}
{com}. 
. di "`chi_stat'"
{res}.009862956701897
{txt}
{com}. 
. local p_value = 1-chi2(1, `chi_stat')
{txt}
{com}. 
. di "`p_value'"
{res}.9208902176923863
{txt}
{com}. 
{txt}end of do-file

{com}. 
. //Emissions Controls
. do RegDIDEmissions
{txt}
{com}. eststo clear
{txt}
{com}. 
. 
. if("`c(os)'"=="Windows"){c -(}
.         local tableSaveDir = "ReviewResponseResults\"
.         local plotSaveDir = "ReviewResponseResults\"
.         local pythonSaveDir = "PythonScripts\"
. {c )-}
{txt}
{com}. else{c -(}
.         local tableSaveDir = "ReviewResponseResults/"
.         local plotSaveDir = "ReviewResponseResults/"
.         local pythonSaveDir = "PythonScripts/"
. {c )-}
{txt}
{com}. 
. //Establish Control Variable Sets
. //Spec1 controls are the same for both registrations and VMT 
. local spec1Controls = "c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.emissionind"
{txt}
{com}. 
. //Other controls are not the same for both registrations and VMT 
. //Registration Controls
. local spec2Controls = "`spec1Controls' i.transactionDataDummy"
{txt}
{com}. local spec3Controls = "`spec2Controls' i.regDummyExtSpec3"
{txt}
{com}. local spec4Controls = "`spec2Controls' i.regDummyExtSpec4"
{txt}
{com}. 
. //Absorb Vars are always time and state fixed effects
. local absorbVars = "ib51.stateGroup ib1995.year"
{txt}
{com}. 
. //Establish Cluster Variable
. local clusterVar = "stateGroup year"
{txt}
{com}. 
. //Establish primary null
. local primaryNull = 1.6
{txt}
{com}. local altNull = 1
{txt}
{com}. local altNull2 = 0.3
{txt}
{com}. local altNull3 = 0
{txt}
{com}. local altNull4 = -2.5
{txt}
{com}. 
. frame create emissions
{txt}
{com}. frame change emissions
{txt}
{com}. 
. if("`c(os)'"=="Windows"){c -(}
.         local dataFile = "CleanedData\EmissionsProgramsV2.xlsx"
. {c )-}
{txt}
{com}. else{c -(}
.         local dataFile = "CleanedData/EmissionsProgramsV2.xlsx"
. {c )-}
{txt}
{com}. 
. import excel using "`dataFile'", first sheet("Clean") case(l)
{res}{text}(4 vars, 51 obs)

{com}. 
. frame change default
{txt}
{com}. frlink m:1 state, frame(emissions)
{res}{txt}  (all observations in frame {bf:default} matched)
{res}{txt}
{com}. frget stateemissionsprogram startemission endemission, from(emissions)
{res}{txt}(733 missing values generated)
{res}{txt}(733 missing values generated)
{res}{txt}{p 2 3 2}
(3 variables copied from linked frame)
{p_end}

{com}. 
. gen emissionind = 0
{txt}
{com}. replace emissionind = 1 if year>=startemission & year<=endemission & stateemissionsprogram==1
{txt}(1,090 real changes made)

{com}. 
. frame drop emissions
{txt}
{com}. 
. //non-normalized models
. local treatmentVar = "1.nosafetyind"
{txt}
{com}. 
. 
. local fsVarsSpec2 = "logregistrations i.nosafetyind `spec2RegControls' i.emissionind"
{txt}
{com}. local rfVarsSpec2 = "logvmt i.nosafetyind `spec2VMTControls' i.emissionind"
{txt}
{com}. 
. 
. //Estimate Models
. //Estimate Spec. 1 DiD Model
. regFWL logregistrations, nosafetyind, `spec1Controls', `absorbVars', `clusterVar', spec1ResEmissions
absorb: ib51.stateGroup ib1995.year

{txt}scalars:
                  e(N) =  {res}2424
               {txt}e(df_m) =  {res}1
               {txt}e(df_r) =  {res}2423
                  {txt}e(F) =  {res}33.04974310923899
                 {txt}e(r2) =  {res}.0134564632503736
               {txt}e(rmse) =  {res}.0501185903003781
                {txt}e(mss) =  {res}.0830167604697003
                {txt}e(rss) =  {res}6.086268506028201
               {txt}e(r2_a) =  {res}.0130493053730523
                 {txt}e(ll) =  {res}3816.905679308549
               {txt}e(rank) =  {res}1

{txt}macros:
            e(cmdline) : "{res}regress logregistrations_res  nosafetyind_res, nocon{txt}"
              e(title) : "{res}Linear regression{txt}"
          e(marginsok) : "{res}XB default{txt}"
                e(vce) : "{res}ols{txt}"
             e(depvar) : "{res}logregistrations_res{txt}"
                e(cmd) : "{res}regress{txt}"
         e(properties) : "{res}b V{txt}"
            e(predict) : "{res}regres_p{txt}"
              e(model) : "{res}ols{txt}"
          e(estat_cmd) : "{res}regress_estat{txt}"

matrices:
                  e(b) : {res} 1 x 1
                  {txt}e(V) : {res} 1 x 1
               {txt}e(beta) : {res} 1 x 1

{txt}functions:
             e(sample)   
{res}
{txt}{space 0}{space 13}{c |}{res}{txt}{space 1}{lalign 9:mean}{space 1}{c |}{res}{txt}{space 1}{lalign 9:lnvar}{space 1}
{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:nosafet~s}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:mean}}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:nosafetyin~s}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0002154}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:lnvar}}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:_cons}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0006707}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0169904}}}{space 1}

{com}. eststo spec1
{txt}
{com}. local df = e(N_clust)-1
{txt}
{com}. addRobustFStat "mean:nosafetyind_res"

{txt}added scalar:
              e(fStat) =  {res}13.163028
{txt}
{com}. addTreat "mean:nosafetyind_res"
hello
5
mean
nosafetyind_res

{p 0 7}{space 1}{text:( 1)}{space 1} {res}[mean]nosafetyind_res = 0{p_end}

{txt}{col 12}chi2(  1) ={res}   13.16
{txt}{col 10}Prob > chi2 =  {res}  0.0003
hello2

{txt}added macro:
             e(treatb) : "{res:0.053***}"

{com}. estadd local dsc = "None" 

{txt}added macro:
                e(dsc) : "{res:None}"

{com}. estadd local groupFE = "Y"

{txt}added macro:
            e(groupFE) : "{res:Y}"

{com}. estadd local timeFE = "Y"

{txt}added macro:
             e(timeFE) : "{res:Y}"

{com}. estadd local timeTrend = "Y"

{txt}added macro:
          e(timeTrend) : "{res:Y}"

{com}. estadd local quadTrend = "Y"

{txt}added macro:
          e(quadTrend) : "{res:Y}"

{com}. estadd local commonControls = "Y"

{txt}added macro:
     e(commonControls) : "{res:Y}"

{com}. estadd local emissionsControls = "Y"

{txt}added macro:
  e(emissionsControls) : "{res:Y}"

{com}. estadd local modelNum = "(1)"

{txt}added macro:
           e(modelNum) : "{res:(1)}"

{com}. 
. //Estimate Spec. 2 DiD Model 
. di "absorb og: `absorbVars'"
{res}absorb og: ib51.stateGroup ib1995.year
{txt}
{com}. regFWL logregistrations, nosafetyind, `spec2Controls', `absorbVars', `clusterVar', spec2ResEmissions
absorb: ib51.stateGroup ib1995.year

{txt}scalars:
                  e(N) =  {res}2424
               {txt}e(df_m) =  {res}1
               {txt}e(df_r) =  {res}2423
                  {txt}e(F) =  {res}35.30336492098264
                 {txt}e(r2) =  {res}.0143608658820338
               {txt}e(rmse) =  {res}.0477471919630849
                {txt}e(mss) =  {res}.0804844115425087
                {txt}e(rss) =  {res}5.523941686691509
               {txt}e(r2_a) =  {res}.0139540812620923
                 {txt}e(ll) =  {res}3934.401189192723
               {txt}e(rank) =  {res}1

{txt}macros:
            e(cmdline) : "{res}regress logregistrations_res  nosafetyind_res, nocon{txt}"
              e(title) : "{res}Linear regression{txt}"
          e(marginsok) : "{res}XB default{txt}"
                e(vce) : "{res}ols{txt}"
             e(depvar) : "{res}logregistrations_res{txt}"
                e(cmd) : "{res}regress{txt}"
         e(properties) : "{res}b V{txt}"
            e(predict) : "{res}regres_p{txt}"
              e(model) : "{res}ols{txt}"
          e(estat_cmd) : "{res}regress_estat{txt}"

matrices:
                  e(b) : {res} 1 x 1
                  {txt}e(V) : {res} 1 x 1
               {txt}e(beta) : {res} 1 x 1

{txt}functions:
             e(sample)   
{res}
{txt}{space 0}{space 13}{c |}{res}{txt}{space 1}{lalign 9:mean}{space 1}{c |}{res}{txt}{space 1}{lalign 9:lnvar}{space 1}
{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:nosafet~s}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:mean}}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:nosafetyin~s}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0002275}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:lnvar}}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:_cons}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0006156}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0171707}}}{space 1}

{com}. eststo spec2
{txt}
{com}. local df = e(N_clust)-1
{txt}
{com}. addRobustFStat "mean:nosafetyind_res"

{txt}added scalar:
              e(fStat) =  {res}12.9888
{txt}
{com}. addTreat "mean:nosafetyind_res"
hello
5
mean
nosafetyind_res

{p 0 7}{space 1}{text:( 1)}{space 1} {res}[mean]nosafetyind_res = 0{p_end}

{txt}{col 12}chi2(  1) ={res}   12.99
{txt}{col 10}Prob > chi2 =  {res}  0.0003
hello2

{txt}added macro:
             e(treatb) : "{res:0.054***}"

{com}. 
. estadd local dsc = "Documented" 

{txt}added macro:
                e(dsc) : "{res:Documented}"

{com}. estadd local groupFE = "Y"

{txt}added macro:
            e(groupFE) : "{res:Y}"

{com}. estadd local timeFE = "Y"

{txt}added macro:
             e(timeFE) : "{res:Y}"

{com}. estadd local timeTrend = "Y"

{txt}added macro:
          e(timeTrend) : "{res:Y}"

{com}. estadd local quadTrend = "Y"

{txt}added macro:
          e(quadTrend) : "{res:Y}"

{com}. estadd local commonControls = "Y"

{txt}added macro:
     e(commonControls) : "{res:Y}"

{com}. estadd local emissionsControls = "Y"

{txt}added macro:
  e(emissionsControls) : "{res:Y}"

{com}. estadd local modelNum = "(2)"

{txt}added macro:
           e(modelNum) : "{res:(2)}"

{com}. 
. //Estimate Spec. 3 DiD Model
. regFWL logregistrations, nosafetyind, `spec3Controls', `absorbVars', `clusterVar', spec3ResEmissions
absorb: ib51.stateGroup ib1995.year

{txt}scalars:
                  e(N) =  {res}2424
               {txt}e(df_m) =  {res}1
               {txt}e(df_r) =  {res}2423
                  {txt}e(F) =  {res}17.96075660862686
                 {txt}e(r2) =  {res}.0073580685637817
               {txt}e(rmse) =  {res}.0422514232088242
                {txt}e(mss) =  {res}.0320632331112334
                {txt}e(rss) =  {res}4.325497835163749
               {txt}e(r2_a) =  {res}.0069483938087523
                 {txt}e(ll) =  {res}4230.813289236297
               {txt}e(rank) =  {res}1

{txt}macros:
            e(cmdline) : "{res}regress logregistrations_res  nosafetyind_res, nocon{txt}"
              e(title) : "{res}Linear regression{txt}"
          e(marginsok) : "{res}XB default{txt}"
                e(vce) : "{res}ols{txt}"
             e(depvar) : "{res}logregistrations_res{txt}"
                e(cmd) : "{res}regress{txt}"
         e(properties) : "{res}b V{txt}"
            e(predict) : "{res}regres_p{txt}"
              e(model) : "{res}ols{txt}"
          e(estat_cmd) : "{res}regress_estat{txt}"

matrices:
                  e(b) : {res} 1 x 1
                  {txt}e(V) : {res} 1 x 1
               {txt}e(beta) : {res} 1 x 1

{txt}functions:
             e(sample)   
{res}
{txt}{space 0}{space 13}{c |}{res}{txt}{space 1}{lalign 9:mean}{space 1}{c |}{res}{txt}{space 1}{lalign 9:lnvar}{space 1}
{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:nosafet~s}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:mean}}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:nosafetyin~s}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0001924}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:lnvar}}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:_cons}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0002135}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0154505}}}{space 1}

{com}. eststo spec3
{txt}
{com}. local df = e(N_clust)-1
{txt}
{com}. addRobustFStat "mean:nosafetyind_res"

{txt}added scalar:
              e(fStat) =  {res}6.2512591
{txt}
{com}. addTreat "mean:nosafetyind_res"
hello
5
mean
nosafetyind_res

{p 0 7}{space 1}{text:( 1)}{space 1} {res}[mean]nosafetyind_res = 0{p_end}

{txt}{col 12}chi2(  1) ={res}    6.25
{txt}{col 10}Prob > chi2 =  {res}  0.0124
hello2

{txt}added macro:
             e(treatb) : "{res:0.035**}"

{com}. estadd local dsc = "\makecell{c -(}Large \nextline Undocumented{c )-}" 

{txt}added macro:
                e(dsc) : "{res:\makecell{Large \nextline Undocumented}}"

{com}. estadd local groupFE = "Y"

{txt}added macro:
            e(groupFE) : "{res:Y}"

{com}. estadd local timeFE = "Y"

{txt}added macro:
             e(timeFE) : "{res:Y}"

{com}. estadd local timeTrend = "Y"

{txt}added macro:
          e(timeTrend) : "{res:Y}"

{com}. estadd local quadTrend = "Y"

{txt}added macro:
          e(quadTrend) : "{res:Y}"

{com}. estadd local commonControls = "Y"

{txt}added macro:
     e(commonControls) : "{res:Y}"

{com}. estadd local emissionsControls = "Y"

{txt}added macro:
  e(emissionsControls) : "{res:Y}"

{com}. estadd local modelNum = "(3)"

{txt}added macro:
           e(modelNum) : "{res:(3)}"

{com}. 
. //Estimate Spec. 4 Model
. regFWL logregistrations, nosafetyind, `spec4Controls', `absorbVars', `clusterVar', spec4ResEmissions
absorb: ib51.stateGroup ib1995.year

{txt}scalars:
                  e(N) =  {res}2424
               {txt}e(df_m) =  {res}1
               {txt}e(df_r) =  {res}2423
                  {txt}e(F) =  {res}11.56766521758918
                 {txt}e(r2) =  {res}.0047514248147034
               {txt}e(rmse) =  {res}.03602341290168
                {txt}e(mss) =  {res}.0150112004107781
                {txt}e(rss) =  {res}3.144293849376773
               {txt}e(r2_a) =  {res}.0043406742677842
                 {txt}e(ll) =  {res}4617.366031810195
               {txt}e(rank) =  {res}1

{txt}macros:
            e(cmdline) : "{res}regress logregistrations_res  nosafetyind_res, nocon{txt}"
              e(title) : "{res}Linear regression{txt}"
          e(marginsok) : "{res}XB default{txt}"
                e(vce) : "{res}ols{txt}"
             e(depvar) : "{res}logregistrations_res{txt}"
                e(cmd) : "{res}regress{txt}"
         e(properties) : "{res}b V{txt}"
            e(predict) : "{res}regres_p{txt}"
              e(model) : "{res}ols{txt}"
          e(estat_cmd) : "{res}regress_estat{txt}"

matrices:
                  e(b) : {res} 1 x 1
                  {txt}e(V) : {res} 1 x 1
               {txt}e(beta) : {res} 1 x 1

{txt}functions:
             e(sample)   
{res}
{txt}{space 0}{space 13}{c |}{res}{txt}{space 1}{lalign 9:mean}{space 1}{c |}{res}{txt}{space 1}{lalign 9:lnvar}{space 1}
{space 0}{space 0}{ralign 12:}{space 1}{c |}{space 1}{ralign 9:nosafet~s}{space 1}{c |}{space 1}{ralign 9:_cons}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:mean}}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:nosafetyin~s}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0001785}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf:{space 9}}}}{space 1}
{space 0}{hline 13}{c   +}{hline 11}{c   +}{hline 11}
{space 0}{res:{lalign 13:lnvar}}{c |}{space 11}{c |}{space 11}
{space 0}{space 0}{ralign 12:_cons}{space 1}{c |}{space 1}{ralign 9:{res:{sf:-.0000197}}}{space 1}{c |}{space 1}{ralign 9:{res:{sf: .0214171}}}{space 1}

{com}. eststo spec4
{txt}
{com}. local df = e(N_clust)-1
{txt}
{com}. addRobustFStat "mean:nosafetyind_res"

{txt}added scalar:
              e(fStat) =  {res}3.2949239
{txt}
{com}. addTreat "mean:nosafetyind_res"
hello
5
mean
nosafetyind_res

{p 0 7}{space 1}{text:( 1)}{space 1} {res}[mean]nosafetyind_res = 0{p_end}

{txt}{col 12}chi2(  1) ={res}    3.29
{txt}{col 10}Prob > chi2 =  {res}  0.0695
hello2

{txt}added macro:
             e(treatb) : "{res:0.024*}"

{com}. estadd local dsc = "\makecell{c -(}Small \nextline Undocumented{c )-}" 

{txt}added macro:
                e(dsc) : "{res:\makecell{Small \nextline Undocumented}}"

{com}. estadd local groupFE = "Y"

{txt}added macro:
            e(groupFE) : "{res:Y}"

{com}. estadd local timeFE = "Y"

{txt}added macro:
             e(timeFE) : "{res:Y}"

{com}. estadd local timeTrend = "Y"

{txt}added macro:
          e(timeTrend) : "{res:Y}"

{com}. estadd local quadTrend = "Y"

{txt}added macro:
          e(quadTrend) : "{res:Y}"

{com}. estadd local commonControls = "Y"

{txt}added macro:
     e(commonControls) : "{res:Y}"

{com}. estadd local emissionsControls = "Y"

{txt}added macro:
  e(emissionsControls) : "{res:Y}"

{com}. estadd local modelNum = "(4)"

{txt}added macro:
           e(modelNum) : "{res:(4)}"

{com}. 
. //Export Model Results to TeX Files
. //Establish Format
. local fmtDiD = `"drop(*) nocon label compress starlevels(* 0.1 ** 0.05 *** 0.01) nodepvar nomtitle nonumbers not nostar noline"'
{txt}
{com}. 
. 
. local noteString = "\hline \hline \end{c -(}tabular{c )-} \vspace{c -(}0.2cm{c )-} \begin{c -(}tablenotes{c )-} \begin{c -(}spacing{c )-}{c -(}0{c )-} \begin{c -(}footnotesize{c )-} \item \textbf{c -(}Notes:{c )-} This table presents difference-in-differences estimates of the impact of the removal of safety inspections on the log of vehicle registrations.  The unit of observation is state-year. The four specifications pertaining to different levels of ``Data Source Controls'' (DSCs) and control specifications are documented in Table \cref{c -(}ssec:Spec{c )-}. Standard errors, reported in parentheses, are clustered by state. * p\textless 0.1, ** p\textless 0.05, *** p\textless 0.01 \end{c -(}footnotesize{c )-} \end{c -(}spacing{c )-} \end{c -(}tablenotes{c )-} \end{c -(}table{c )-}"
{txt}
{com}. 
. //Export Table
. esttab spec1 spec2 spec3 spec4 using "`tableSaveDir'RegDiDEmissions.tex", `fmtDiD' title("Diff-in-Diff Results Controlling for Emissions Inspections Programs \label{c -(}tab:RegDiDEmissions{c )-}") stats(modelNum treatb treatse dsc groupFE timeFE timeTrend quadTrend commonControls emissionsControls fStat N r2, labels("\hline \hline \multicolumn{c -(}5{c )-}{c -(}c{c )-}{c -(}Dep. Var.: Log Number of Vehicle Registrations{c )-} \\ " "Removal of" "Safety Inspections" "\makecell[l]{c -(}Data Source \nextline Controls{c )-}" "State Fixed Effects" "Year Fixed Effects" "\makecell[l]{c -(}State-Specific Linear \\ Time Trends{c )-}" "\makecell[l]{c -(}State-Specific Quadratic \\ Time Trends{c )-}" "Common Controls" "\makecell[l]{c -(}Emission Inspections \\ Controls{c )-}" "Robust F-Stat" "Number of Obs." "R\textsuperscript{c -(}2{c )-}")fmt(%8.3f %8.3f %8.3f %8.3f  %8.3f  %8.3f  %8.3f  %8.3f %8.3f %8.0fc %8.3f)) replace postfoot("`noteString'")
{res}{txt}(output written to {browse  `"ReviewResponseResults/RegDiDEmissions.tex"'})

{com}. 
. 
{txt}end of do-file

{com}. do LoadDataVMT
{txt}
{com}. clear
{txt}
{com}. //Load Data for travel analysis
. 
. 
. 
. 
. if("`c(os)'"=="Windows"){c -(}
.         local dataFile = "CleanedData\FHWACleanV4.csv"
. {c )-}
{txt}
{com}. else{c -(}
.         local dataFile = "CleanedData/FHWACleanV4.csv"
. {c )-}
{txt}
{com}. 
. import delimited using "`dataFile'"
{res}{txt}(encoding automatically selected: ISO-8859-1)
{res}{text}(90 vars, 3,009 obs)

{com}. 
. //Add State Codes to all states
. sort state
{txt}
{com}. egen tempStateCode = mode(statecode), by(state)
{txt}
{com}. replace statecode = tempStateCode
{txt}(357 real changes made)

{com}. drop tempStateCode
{txt}
{com}. 
. //Label Variables
. label var logregistrations "Log Total Registrations"
{txt}
{com}. label var logvmt "Log VMT"
{txt}
{com}. label var loglicenseddrivers "Log Licensed Drivers" 
{txt}
{com}. label var logjointpopulation "Log Total Population" 
{txt}
{com}. label var logrealmeangasprice "Log Mean Gas Price" 
{txt}
{com}. label var logemployment  "Log Employment"
{txt}
{com}. label var logrealjointincome  "Log Total Income"
{txt}
{com}. label var logmetropop  "Log (1 + Metro Population)"
{txt}
{com}. label var lognonmetropop  "Log (1 + Non-Metro Population)"
{txt}
{com}. label var logmetrorealinc  "Log (1 + Metro Income)"
{txt}
{com}. label var lognonmetrorealinc  "Log (1 + Non-Metro Income)"
{txt}
{com}. label var logrealstategdp  "Log State GDP"
{txt}
{com}. label var logpopulation  "Log Population"
{txt}
{com}. label var logrealtotalincome  "Log Total Income"
{txt}
{com}. label var logroadmileage "Log Road Mileage"
{txt}
{com}. label var nosafetyind "Treatment"
{txt}
{com}. 
. 
. //Create Inverse Hyperbolic Sine Variables 
. gen asinhMetroInc = asinh(realmetroincome2018m)
{txt}(459 missing values generated)

{com}. gen asinhNonMetroInc = asinh(realnonmetroincome2018m)
{txt}(459 missing values generated)

{com}. 
. gen asinhMetroPop = asinh(metropopulation)
{txt}(459 missing values generated)

{com}. gen asinhNonMetroPop = asinh(nonmetropopulation)
{txt}(459 missing values generated)

{com}. 
. //Per capita model
. //construct outcome variable
. gen logRegPerCapita = logregistrations-log(metropopulation + nonmetropopulation)
{txt}(510 missing values generated)

{com}. gen logVMTPerCapita = logvmt-log(metropopulation + nonmetropopulation)
{txt}(510 missing values generated)

{com}. 
. //Label Asinh variables
. label var asinhMetroInc "Asinh(Metro Income)"
{txt}
{com}. label var asinhNonMetroInc "Asinh(Non-Metro Income)"
{txt}
{com}. 
. label var asinhMetroPop "Asinh(Metro Population)"
{txt}
{com}. label var asinhNonMetroPop "Asinh(Non-Metro Population)"
{txt}
{com}. 
. //Label treatment variables
. 
. label define nosafetyind 0 "No Treatment" 1 "Treatment"
{txt}
{com}. label values nosafetyind nosafetyind
{txt}
{com}. 
. 
. //Generate State Dummies
. egen stateGroup = group(state)
{txt}
{com}. 
. //Drop Datapoints that are replications of past data for registrations
. drop if statecode=="CO" & year==2006
{txt}(1 observation deleted)

{com}. drop if statecode=="IN" & (year==2006 | year==2007 | year==2009)
{txt}(3 observations deleted)

{com}. drop if statecode=="MT" & year==2005
{txt}(1 observation deleted)

{com}. drop if statecode=="NJ" & year==2008
{txt}(1 observation deleted)

{com}. drop if statecode=="PR" & (year==2002 | year==2003 | year==2005 | year==2008 | year==2009 | year==2010)
{txt}(0 observations deleted)

{com}. drop if statecode=="TX" & year==2009
{txt}(1 observation deleted)

{com}. drop if statecode=="IL" & year==2011
{txt}(1 observation deleted)

{com}. drop if statecode=="NH" & year==2012
{txt}(1 observation deleted)

{com}. drop if statecode=="NY" & year==2012
{txt}(1 observation deleted)

{com}. //Drop Datapoints that are replications of past data for VMT
. drop if statecode=="MO" & year == 2003
{txt}(1 observation deleted)

{com}. drop if statecode=="IN" & (year == 2004 | year==2009)
{txt}(1 observation deleted)

{com}. drop if statecode=="NV" & year == 2004
{txt}(1 observation deleted)

{com}. drop if statecode=="NH" & year == 2004
{txt}(1 observation deleted)

{com}. drop if statecode=="NY" & year == 2005
{txt}(1 observation deleted)

{com}. drop if statecode=="AZ" & year == 2009
{txt}(1 observation deleted)

{com}. drop if statecode=="WY" & year == 2010
{txt}(1 observation deleted)

{com}. drop if statecode=="PR" & (year == 2011 | year == 2012 | year == 2013 | year == 2015 | year == 2016)
{txt}(0 observations deleted)

{com}. 
. //Drop if data is prior to 1970
. drop if year<1970
{txt}(510 observations deleted)

{com}. 
. //Normalize differenece of outcome variables for identification of extreme points
. 
. sort stateGroup year
{txt}
{com}. xtset stateGroup year
{res}
{col 1}{txt:Panel variable: }{res:stateGroup}{txt: (unbalanced)}
{p 1 16 2}{txt:Time variable: }{res:year}{txt:, }{res:{bind:1970}}{txt: to }{res:{bind:2018}}{txt:, but with gaps}{p_end}
{txt}{col 10}Delta: {res}1 unit
{txt}
{com}. 
. gen DiffLogReg = d.logregistrations
{txt}(118 missing values generated)

{com}. gen DiffLogVMT = d.logvmt
{txt}(118 missing values generated)

{com}. gen DiffLogRegPerCapita = d.logRegPerCapita
{txt}(118 missing values generated)

{com}. gen DiffLogVMTPerCapita = d.logVMTPerCapita
{txt}(118 missing values generated)

{com}. 
. local normVarList = "DiffLogReg DiffLogVMT DiffLogRegPerCapita DiffLogVMTPerCapita"
{txt}
{com}. 
. sort stateGroup
{txt}
{com}. 
. foreach varToNorm in `normVarList'{c -(}
{txt}  2{com}.         
.         by stateGroup: egen tempMean = mean(`varToNorm')
{txt}  3{com}.         by stateGroup: egen tempSD = sd(`varToNorm')
{txt}  4{com}.         by stateGroup: egen tempNumData = count(`varToNorm')
{txt}  5{com}.         gen tempSE = tempSD/sqrt(tempNumData)
{txt}  6{com}.         
.         gen norm`varToNorm' = (`varToNorm'-tempMean)/tempSD
{txt}  7{com}.         
.         drop tempMean tempSD tempNumData tempSE
{txt}  8{com}.         
.         di "`varToNorm'"
{txt}  9{com}.         
. {c )-}
{txt}(118 missing values generated)
DiffLogReg
(118 missing values generated)
DiffLogVMT
(118 missing values generated)
DiffLogRegPerCapita
(118 missing values generated)
DiffLogVMTPerCapita

{com}. 
. //Generate Colorado Dummy
. gen coDum1 = 0
{txt}
{com}. gen coDum2 = 0
{txt}
{com}. replace coDum1 = 1 if statecode=="CO" & year>=2002 & year<=2009
{txt}(7 real changes made)

{com}. replace coDum2 = 1 if statecode=="CO" & year>=2010
{txt}(9 real changes made)

{com}. 
. drop if coDum1 == 1
{txt}(7 observations deleted)

{com}. 
. 
. //Generate dummy variable for data footnotes
. gen transactionDataDummy = 0
{txt}
{com}. 
. replace transactionDataDummy = 1 if statecode=="AR" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 2 if statecode=="GA" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 3 if statecode=="IA" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 4 if statecode=="IL" & year>=2012
{txt}(7 real changes made)

{com}. replace transactionDataDummy = 5 if statecode=="KY" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 6 if statecode=="LA" & year>=2012
{txt}(7 real changes made)

{com}. replace transactionDataDummy = 7 if statecode=="ME" & year>=2011 //Maine is a state with what looks to not have a consistent change
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 8 if statecode=="ME" & year>2014
{txt}(4 real changes made)

{com}. replace transactionDataDummy = 9 if statecode=="MI" & year>=2011 //Michigan is a state with what looks to not have a consistent change
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 10 if statecode=="MI" & year>2012
{txt}(6 real changes made)

{com}. replace transactionDataDummy = 11 if statecode=="MN" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 12 if statecode=="NV" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 13 if statecode=="OK" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 14 if statecode=="SD" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 15 if statecode=="TN" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 16 if statecode=="TX" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 17 if statecode=="WA" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 18 if statecode=="WI" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 19 if statecode=="WY" & year>=2011
{txt}(8 real changes made)

{com}. 
. 
. 
. 
. //Local Extreme Discontinuity controls
. 
. sort state year
{txt}
{com}. 
. python
{txt}{hline 47} python (type {cmd:end} to exit) {hline}
{com}>>> 
>>> import numpy as np
>>> import pandas as p 
>>> from sfi import Data 
>>> 
>>> 
>>> def getDSCDummies(data, col, cutoff):
... 
...         tempExtState = None
... 
...         tempIndex = 0
...         stateCol = 0
... 
...         rows, cols = data.shape
... 
...         dummyExt = []
... 
...         for i in range(rows):
...                 tempDiff = float(data[i,col])
...                 tempState = data[i,stateCol]
... 
... 
...                 if(abs(tempDiff)>cutoff):
...                         tempExtState = tempState
...                         tempIndex+=1
... 
...                 if tempState==tempExtState:
...                         dummyExt.append(tempIndex)
...                 else:
...                         dummyExt.append(0)
... 
... 
...         dummyExt = np.array(dummyExt).reshape((-1,1))
...         return dummyExt
... 
>>> dataCols = ['state', 'year', 'normDiffLogReg', 'normDiffLogVMT', 'normDiffLogRegPerCapita', 'normDiffLogVMTPerCapita']
>>> 
>>> data = np.array(Data.get(dataCols, missingval=np.nan))
>>> 
>>> print(data)
{res}[['Alabama' '1970' 'nan' 'nan' 'nan' 'nan']
 ['Alabama' '1971' '1.0640671570008131' '0.3361620217656708'
  '0.9150116516585626' '0.16061868662892634']
 ['Alabama' '1972' '1.0231103264075507' '0.24914037544421433'
  '0.9109946118213749' '0.11750494756107976']
 ...
 ['Wyoming' '2016' '0.45763583139776387' '-1.6128834808565655'
  '0.7516965179523265' '-1.1845977355288309']
 ['Wyoming' '2017' '-1.1510098900675998' '0.6274459465980643'
  '-0.8234171123760192' '1.2249676800199891']
 ['Wyoming' '2018' 'nan' 'nan' 'nan' 'nan']]
{com}>>> 
>>> regCutoffLow = 2.93 #Spec. 4
>>> regCutoffPrimary = 4.02 #Spec. 3
>>> regCutoffHigh = 7 #Spec. 2
>>> 
>>> vmtCutoffLow = 2.93 #Spec. 4
>>> vmtCutoffPrimary = 4.02 #Spec. 3
>>> vmtCutoffHigh = 7 #Spec. 2
>>> 
>>> regCol = dataCols.index('normDiffLogReg')
>>> vmtCol = dataCols.index('normDiffLogVMT')
>>> 
>>> regPerCapitaCol = dataCols.index('normDiffLogRegPerCapita')
>>> vmtPerCapitaCol = dataCols.index('normDiffLogVMTPerCapita')
>>> 
>>> rows, cols = data.shape
>>> 
>>> regDummyExtLow = getDSCDummies(data, regCol, regCutoffLow)
>>> regDummyExtPrimary = getDSCDummies(data, regCol, regCutoffPrimary)
>>> regDummyExtHigh = getDSCDummies(data, regCol, regCutoffHigh)
>>> 
>>> vmtDummyExtLow = getDSCDummies(data, vmtCol, vmtCutoffLow)
>>> vmtDummyExtPrimary = getDSCDummies(data, vmtCol, vmtCutoffPrimary)
>>> vmtDummyExtHigh = getDSCDummies(data, vmtCol, vmtCutoffHigh)
>>> 
>>> regPerCapitaDummyExtLow = getDSCDummies(data, regPerCapitaCol, regCutoffLow)
>>> regPerCapitaDummyExtPrimary = getDSCDummies(data, regPerCapitaCol, regCutoffPrimary)
>>> regPerCapitaDummyExtHigh = getDSCDummies(data, regPerCapitaCol, regCutoffHigh)
>>> 
>>> vmtPerCapitaDummyExtLow = getDSCDummies(data, vmtPerCapitaCol, vmtCutoffLow)
>>> vmtPerCapitaDummyExtPrimary = getDSCDummies(data, vmtPerCapitaCol, vmtCutoffPrimary)
>>> vmtPerCapitaDummyExtHigh = getDSCDummies(data, vmtPerCapitaCol, vmtCutoffHigh)
>>> 
>>> Data.addVarInt('regDummyExtSpec4')
>>> Data.store("regDummyExtSpec4",None, regDummyExtLow[:])
>>> Data.addVarInt('regDummyExtSpec3')
>>> Data.store("regDummyExtSpec3",None, regDummyExtPrimary[:])
>>> Data.addVarInt('regDummyExtSpec2')
>>> Data.store("regDummyExtSpec2",None, regDummyExtHigh[:])
>>> 
>>> Data.addVarInt('vmtDummyExtSpec4')
>>> Data.store("vmtDummyExtSpec4",None, vmtDummyExtLow[:])
>>> Data.addVarInt('vmtDummyExtSpec3')
>>> Data.store("vmtDummyExtSpec3",None, vmtDummyExtPrimary[:])
>>> Data.addVarInt('vmtDummyExtSpec2')
>>> Data.store("vmtDummyExtSpec2",None, vmtDummyExtHigh[:])
>>> 
>>> 
>>> Data.addVarInt('regPerCapitaDummyExtSpec4')
>>> Data.store("regPerCapitaDummyExtSpec4",None, regPerCapitaDummyExtLow[:])
>>> Data.addVarInt('regPerCapitaDummyExtSpec3')
>>> Data.store("regPerCapitaDummyExtSpec3",None, regPerCapitaDummyExtPrimary[:])
>>> Data.addVarInt('regPerCapitaDummyExtSpec2')
>>> Data.store("regPerCapitaDummyExtSpec2",None, regPerCapitaDummyExtHigh[:])
>>> 
>>> Data.addVarInt('vmtPerCapitaDummyExtSpec4')
>>> Data.store("vmtPerCapitaDummyExtSpec4",None, vmtPerCapitaDummyExtLow[:])
>>> Data.addVarInt('vmtPerCapitaDummyExtSpec3')
>>> Data.store("vmtPerCapitaDummyExtSpec3",None, vmtPerCapitaDummyExtPrimary[:])
>>> Data.addVarInt('vmtPerCapitaDummyExtSpec2')
>>> Data.store("vmtPerCapitaDummyExtSpec2",None, vmtPerCapitaDummyExtHigh[:])
>>>         
>>> end
{txt}{hline}

{com}. 
. 
. //Generate normalized year values to reduce differences in magnitude of covariates.
. //Scale year for better numerical performance
. local yearScale = 1
{txt}
{com}. gen normYear = year/`yearScale'
{txt}
{com}. gen quadYear = (year/1)^2
{txt}
{com}. 
. //Establish treatment interacted with pre-treatment population share in metro areas
. frame copy default MetroShares
{txt}
{com}. frame change MetroShares
{txt}
{com}. keep if year==1970
{txt}(2,424 observations deleted)

{com}. 
. capture gen preTreatMetroShare = metropopulation/(metropopulation+nonmetropopulation)
{txt}
{com}. 
. frame change default 
{txt}
{com}. 
. cap frlink m:1 state, frame(MetroShares)
{txt}
{com}. cap frget preTreatMetroShare, from(MetroShares)
{txt}
{com}. 
. cap gen metroIntTreatment = nosafetyind*preTreatMetroShare
{txt}
{com}. 
. frame drop MetroShares
{txt}
{com}. 
{txt}end of do-file

{com}. do VMTIVEmissions
{txt}
{com}. eststo clear
{txt}
{com}. 
. 
. if("`c(os)'"=="Windows"){c -(}
.         local tableSaveDir = "ReviewResponseResults\"
.         local plotSaveDir = "ReviewResponseResults\"
.         local pythonSaveDir = "PythonScripts\"
. {c )-}
{txt}
{com}. else{c -(}
.         local tableSaveDir = "ReviewResponseResults/"
.         local plotSaveDir = "ReviewResponseResults/"
.         local pythonSaveDir = "PythonScripts/"
. {c )-}
{txt}
{com}. 
. //Establish Control Variable Sets
. //Spec1 controls are the same for both registrations and VMT 
. local spec1Controls = "c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage"
{txt}
{com}. 
. //Other controls are not the same for both registrations and VMT 
. //Registration Controls
. local spec2RegControls = "`spec1Controls' i.transactionDataDummy"
{txt}
{com}. local spec3RegControls = "`spec2RegControls' i.regDummyExtSpec3"
{txt}
{com}. local spec4RegControls = "`spec2RegControls' i.regDummyExtSpec4"
{txt}
{com}. 
. 
. di "`spec3RegControls'"
{res}c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.transactionDataDummy i.regDummyExtSpec3
{txt}
{com}. 
. //VMT Controls
. local spec2VMTControls = "`spec1Controls'"
{txt}
{com}. local spec3VMTControls = "`spec2VMTControls' i.vmtDummyExtSpec3"
{txt}
{com}. local spec4VMTControls = "`spec2VMTControls' i.vmtDummyExtSpec4"
{txt}
{com}. 
. //Absorb Vars are always time and state fixed effects
. local absorbVars = "ib51.stateGroup ib1995.year"
{txt}
{com}. 
. //Establish Cluster Variable
. local clusterVar = "stateGroup year"
{txt}
{com}. 
. //Establish primary null
. local primaryNull = 1.6
{txt}
{com}. local altNull = 1
{txt}
{com}. local altNull2 = 0.3
{txt}
{com}. local altNull3 = 0
{txt}
{com}. local altNull4 = -2.5
{txt}
{com}. 
. frame create emissions
{txt}
{com}. frame change emissions
{txt}
{com}. 
. if("`c(os)'"=="Windows"){c -(}
.         local dataFile = "CleanedData\EmissionsProgramsV2.xlsx"
. {c )-}
{txt}
{com}. else{c -(}
.         local dataFile = "CleanedData/EmissionsProgramsV2.xlsx"
. {c )-}
{txt}
{com}. 
. import excel using "`dataFile'", first sheet("Clean") case(l)
{res}{text}(4 vars, 51 obs)

{com}. 
. frame change default
{txt}
{com}. frlink m:1 state, frame(emissions)
{res}{txt}  (all observations in frame {bf:default} matched)
{res}{txt}
{com}. frget stateemissionsprogram startemission endemission, from(emissions)
{res}{txt}(733 missing values generated)
{res}{txt}(733 missing values generated)
{res}{txt}{p 2 3 2}
(3 variables copied from linked frame)
{p_end}

{com}. 
. gen emissionind = 0
{txt}
{com}. replace emissionind = 1 if year>=startemission & year<=endemission & stateemissionsprogram==1
{txt}(1,090 real changes made)

{com}. 
. frame drop emissions
{txt}
{com}. 
. //non-normalized models
. local treatmentVar = "1.nosafetyind"
{txt}
{com}. 
. 
. local fsVarsSpec2 = "logregistrations i.nosafetyind `spec2RegControls' i.emissionind"
{txt}
{com}. local rfVarsSpec2 = "logvmt i.nosafetyind `spec2VMTControls' i.emissionind"
{txt}
{com}. 
. local fsOut = "logregistrations"
{txt}
{com}. local rfOut = "logvmt"
{txt}
{com}. 
. local treatControl = "nosafetyind"
{txt}
{com}. 
. local fsControlsSpec1 = "`spec1Controls' i.emissionind"
{txt}
{com}. local rfControlsSpec1 = "`spec1Controls' i.emissionind"
{txt}
{com}. 
. 
. local modelTitleSpec1 = "Spec1Emissions"
{txt}
{com}. local nullLowSpec1 = -4
{txt}
{com}. local nullDeltaSpec1 = 0.001
{txt}
{com}. local nullHighSpec1 = 1
{txt}
{com}. 
. runModelFWL `fsOut', `rfOut', `fsControlsSpec1', `rfControlsSpec1', `treatControl', `absorbVars', `clusterVar', `treatmentVar', `modelTitleSpec1', `nullLowSpec1', `nullDeltaSpec1', `nullHighSpec1', `primaryNull', `altNull', `altNull2', `altNull3', `altNull4'
logregistrations
logvmt
c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.emissionind
c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.emissionind
nosafetyind
ib51.stateGroup ib1995.year
Working on:Spec1Emissions

{txt}      Source {c |}       SS           df       MS      Number of obs   ={res}     2,424
{txt}{hline 13}{c +}{hline 34}   F(1, 2423)      = {res}    33.05
{txt}       Model {c |} {res}  .08301676         1   .08301676   {txt}Prob > F        ={res}    0.0000
{txt}    Residual {c |} {res} 6.08626851     2,423  .002511873   {txt}R-squared       ={res}    0.0135
{txt}{hline 13}{c +}{hline 34}   Adj R-squared   ={res}    0.0130
{txt}       Total {c |} {res} 6.16928527     2,424  .002545085   {txt}Root MSE        =   {res} .05012

{txt}{hline 19}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}logregistrations~s{col 20}{c |} Coefficient{col 32}  Std. err.{col 44}      t{col 52}   P>|t|{col 60}     [95% con{col 73}f. interval]
{hline 19}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
fs_nosafetyind_res {c |}{col 20}{res}{space 2} .0532531{col 32}{space 2} .0092632{col 43}{space 1}    5.75{col 52}{space 3}0.000{col 60}{space 4} .0350885{col 73}{space 3} .0714176
{txt}{hline 19}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}Current approach can handle two-way clustering. Higher dimensional clustering will produce incorrect results.

{txt}scalars:
              r(covar) =  {res}.0000259109536037
           {txt}r(covarLow) =  {res}.0000259109536037
          {txt}r(covarHigh) =  {res}.0000259109536037
           {txt}r(deltaVar) =  {res}.0002845415852729
              {txt}r(piVar) =  {res}.0002154433972943
   {txt}r(covarUncorrected) =  {res}.0000242193361983
  {txt}r(deltaVarUncorrect
    ed)                =  {res}.00026596505947
   {txt}r(piVarUncorrected) =  {res}.0002013780021603
              {txt}r(delta) =  {res}-.0096017744134962
                 {txt}r(pi) =  {res}.0532530521703231
       {txt}r(rfCorrection) =  {res}1.069845737781825
       {txt}r(fsCorrection) =  {res}1.069845737781825
                  {txt}r(N) =  {res}2424
             {txt}r(nClust) =  {res}48
            {txt}r(nClust2) =  {res}48
            {txt}r(nClust1) =  {res}51
  {txt}r(covarUncorrectedR) =  {res}2.01655271599e-06
  {txt}r(deltaVarUncorrect
    edR)               =  {res}.0000396805449167
  {txt}r(piVarUncorrectedR) =  {res}.0000903020694787
  {txt}r(covarUncorrected2) =  {res}-1.85902072489e-06
  {txt}r(deltaVarUncorrect
    ed2)               =  {res}.0000336002660839
  {txt}r(piVarUncorrected2) =  {res}.000103736870988
  {txt}r(covarUncorrected1) =  {res}.0000280949096392
  {txt}r(deltaVarUncorrect
    ed1)               =  {res}.0002720453383028
  {txt}r(piVarUncorrected1) =  {res}.000187943200651
                {txt}r(rfK) =  {res}111
                {txt}r(fsK) =  {res}111
{txt}
{com}. 
. local fsControlsSpec2 = "`spec2RegControls' i.emissionind"
{txt}
{com}. local rfControlsSpec2 = "`spec2VMTControls' i.emissionind"
{txt}
{com}. 
. 
. local modelTitleSpec2 = "Spec2Emissions"
{txt}
{com}. local nullLowSpec2 = -4
{txt}
{com}. local nullDeltaSpec2 = 0.001
{txt}
{com}. local nullHighSpec2 = 1
{txt}
{com}. 
. runModelFWL `fsOut', `rfOut', `fsControlsSpec2', `rfControlsSpec2', `treatControl', `absorbVars', `clusterVar', `treatmentVar', `modelTitleSpec2', `nullLowSpec2', `nullDeltaSpec2', `nullHighSpec2', `primaryNull', `altNull', `altNull2', `altNull3', `altNull4'
logregistrations
logvmt
c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.transactionDataDummy i.emissionind
c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.emissionind
nosafetyind
ib51.stateGroup ib1995.year
Working on:Spec2Emissions

{txt}      Source {c |}       SS           df       MS      Number of obs   ={res}     2,424
{txt}{hline 13}{c +}{hline 34}   F(1, 2423)      = {res}    35.30
{txt}       Model {c |} {res} .080484412         1  .080484412   {txt}Prob > F        ={res}    0.0000
{txt}    Residual {c |} {res} 5.52394169     2,423  .002279794   {txt}R-squared       ={res}    0.0144
{txt}{hline 13}{c +}{hline 34}   Adj R-squared   ={res}    0.0140
{txt}       Total {c |} {res}  5.6044261     2,424  .002312057   {txt}Root MSE        =   {res} .04775

{txt}{hline 19}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}logregistrations~s{col 20}{c |} Coefficient{col 32}  Std. err.{col 44}      t{col 52}   P>|t|{col 60}     [95% con{col 73}f. interval]
{hline 19}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
fs_nosafetyind_res {c |}{col 20}{res}{space 2} .0543644{col 32}{space 2} .0091497{col 43}{space 1}    5.94{col 52}{space 3}0.000{col 60}{space 4} .0364223{col 73}{space 3} .0723064
{txt}{hline 19}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}Current approach can handle two-way clustering. Higher dimensional clustering will produce incorrect results.

{txt}scalars:
              r(covar) =  {res}.0000364039829429
           {txt}r(covarLow) =  {res}.0000364039829429
          {txt}r(covarHigh) =  {res}.0000367054980589
           {txt}r(deltaVar) =  {res}.0002868982941308
              {txt}r(piVar) =  {res}.0002275408524375
   {txt}r(covarUncorrected) =  {res}.0000340273196942
  {txt}r(deltaVarUncorrect
    ed)                =  {res}.00026596505947
   {txt}r(piVarUncorrected) =  {res}.000210938571572
              {txt}r(delta) =  {res}-.0096017744134962
                 {txt}r(pi) =  {res}.054364351167051
       {txt}r(rfCorrection) =  {res}1.069845737781825
       {txt}r(fsCorrection) =  {res}1.078706709454822
                  {txt}r(N) =  {res}2424
             {txt}r(nClust) =  {res}48
            {txt}r(nClust2) =  {res}48
            {txt}r(nClust1) =  {res}51
  {txt}r(covarUncorrectedR) =  {res}9.30950277249e-07
  {txt}r(deltaVarUncorrect
    edR)               =  {res}.0000396805449167
  {txt}r(piVarUncorrectedR) =  {res}.0000921437909359
  {txt}r(covarUncorrected2) =  {res}-1.63084038450e-06
  {txt}r(deltaVarUncorrect
    ed2)               =  {res}.0000336002660839
  {txt}r(piVarUncorrected2) =  {res}.0001264189533276
  {txt}r(covarUncorrected1) =  {res}.0000365891103559
  {txt}r(deltaVarUncorrect
    ed1)               =  {res}.0002720453383028
  {txt}r(piVarUncorrected1) =  {res}.0001766634091803
                {txt}r(rfK) =  {res}111
                {txt}r(fsK) =  {res}130
{txt}
{com}. // runModel `fsVarsSpec2', `rfVarsSpec2', `clusterVar', `treatmentVar', `modelTitleSpec2', `nullLowSpec2', `nullDeltaSpec2', `nullHighSpec2', `primaryNull', `altNull', `altNull2', `altNull3', `altNull4'
. //
. // python script "`pythonSaveDir'combineIV.py" 
. //
. //
. // constructTable VMTPerCapitaiv; Fleet Travel Distance Per Capita; Spec1PerCapita Spec2PerCapita Spec3PerCapita Spec4PerCapita; `primaryNull'; `altNull'; `altNull2'; `altNull3'; `altNull4'
. // constructTable VMTiv; Fleet Travel Distance ; Spec1 Spec2 Spec3 Spec4; `primaryNull'; `altNull'; `altNull2'; `altNull3'; `altNull4'
. 
{txt}end of do-file

{com}. 
. // Gas Use
. do LoadDataGasUse
{txt}
{com}. clear 
{txt}
{com}. //Load Data for gas use analysis
. if("`c(os)'"=="Windows"){c -(}
.         local dataFile = "CleanedData\FHWACleanV4.csv"
. {c )-}
{txt}
{com}. else{c -(}
.         local dataFile = "CleanedData/FHWACleanV4.csv"
. {c )-}
{txt}
{com}. 
. import delimited using "`dataFile'"
{res}{txt}(encoding automatically selected: ISO-8859-1)
{res}{text}(90 vars, 3,009 obs)

{com}. 
. //Add State Codes to all states
. sort state
{txt}
{com}. egen tempStateCode = mode(statecode), by(state)
{txt}
{com}. replace statecode = tempStateCode
{txt}(357 real changes made)

{com}. drop tempStateCode
{txt}
{com}. 
. //Label Variables
. label var logregistrations "Log Total Registrations"
{txt}
{com}. label var logvmt "Log VMT"
{txt}
{com}. label var loglicenseddrivers "Log Licensed Drivers" 
{txt}
{com}. label var logjointpopulation "Log Total Population" 
{txt}
{com}. label var logrealmeangasprice "Log Mean Gas Price" 
{txt}
{com}. label var logemployment  "Log Employment"
{txt}
{com}. label var logrealjointincome  "Log Total Income"
{txt}
{com}. label var logmetropop  "Log (1 + Metro Population)"
{txt}
{com}. label var lognonmetropop  "Log (1 + Non-Metro Population)"
{txt}
{com}. label var logmetrorealinc  "Log (1 + Metro Income)"
{txt}
{com}. label var lognonmetrorealinc  "Log (1 + Non-Metro Income)"
{txt}
{com}. label var logrealstategdp  "Log State GDP"
{txt}
{com}. label var logpopulation  "Log Population"
{txt}
{com}. label var logrealtotalincome  "Log Total Income"
{txt}
{com}. label var logroadmileage "Log Road Mileage"
{txt}
{com}. label var nosafetyind "Treatment"
{txt}
{com}. 
. 
. //Create Inverse Hyperbolic Sine Variables 
. gen asinhMetroInc = asinh(realmetroincome2018m)
{txt}(459 missing values generated)

{com}. gen asinhNonMetroInc = asinh(realnonmetroincome2018m)
{txt}(459 missing values generated)

{com}. 
. gen asinhMetroPop = asinh(metropopulation)
{txt}(459 missing values generated)

{com}. gen asinhNonMetroPop = asinh(nonmetropopulation)
{txt}(459 missing values generated)

{com}. 
. 
. //Label Asinh variables
. label var asinhMetroInc "Asinh(Metro Income)"
{txt}
{com}. label var asinhNonMetroInc "Asinh(Non-Metro Income)"
{txt}
{com}. 
. label var asinhMetroPop "Asinh(Metro Population)"
{txt}
{com}. label var asinhNonMetroPop "Asinh(Non-Metro Population)"
{txt}
{com}. 
. //per capita models
. //construct outcome variables 
. gen logRegPerCapita = logregistrations-log(metropopulation + nonmetropopulation)
{txt}(510 missing values generated)

{com}. gen logGasUsePerCapita = loghighwaygasuse-log(metropopulation + nonmetropopulation)
{txt}(459 missing values generated)

{com}. 
. 
. //Label treatment variables
. 
. label define nosafetyind 0 "No Treatment" 1 "Treatment"
{txt}
{com}. label values nosafetyind nosafetyind
{txt}
{com}. 
. 
. //Generate State Dummies
. egen stateGroup = group(state)
{txt}
{com}. 
. //Drop Datapoints that are replications of past data for registrations
. drop if statecode=="CO" & year==2006
{txt}(1 observation deleted)

{com}. drop if statecode=="IN" & (year==2006 | year==2007 | year==2009)
{txt}(3 observations deleted)

{com}. drop if statecode=="MT" & year==2005
{txt}(1 observation deleted)

{com}. drop if statecode=="NJ" & year==2008
{txt}(1 observation deleted)

{com}. drop if statecode=="PR" & (year==2002 | year==2003 | year==2005 | year==2008 | year==2009 | year==2010)
{txt}(0 observations deleted)

{com}. drop if statecode=="TX" & year==2009
{txt}(1 observation deleted)

{com}. drop if statecode=="IL" & year==2011
{txt}(1 observation deleted)

{com}. drop if statecode=="NH" & year==2012
{txt}(1 observation deleted)

{com}. drop if statecode=="NY" & year==2012
{txt}(1 observation deleted)

{com}. 
. //Drop Datapoints that are replications of past data for gas use
. drop if statecode=="RI" & (year==2003 | year==2005)
{txt}(2 observations deleted)

{com}. 
. 
. //Drop if data is prior to 1970
. drop if year<1970
{txt}(510 observations deleted)

{com}. 
. //Normalize differenece of outcome variables for identification of extreme points
. 
. sort stateGroup year
{txt}
{com}. xtset stateGroup year
{res}
{col 1}{txt:Panel variable: }{res:stateGroup}{txt: (unbalanced)}
{p 1 16 2}{txt:Time variable: }{res:year}{txt:, }{res:{bind:1970}}{txt: to }{res:{bind:2018}}{txt:, but with gaps}{p_end}
{txt}{col 10}Delta: {res}1 unit
{txt}
{com}. 
. gen DiffLogReg = d.logregistrations
{txt}(113 missing values generated)

{com}. gen DiffLogHighwayGasUse = d.loghighwaygasuse
{txt}(62 missing values generated)

{com}. gen DiffLogRegPerCapita = d.logRegPerCapita
{txt}(113 missing values generated)

{com}. gen DiffLogGasUsePerCapita = d.logGasUsePerCapita
{txt}(62 missing values generated)

{com}. 
. local normVarList = "DiffLogReg DiffLogHighwayGasUse DiffLogRegPerCapita DiffLogGasUsePerCapita"
{txt}
{com}. 
. sort stateGroup
{txt}
{com}. 
. foreach varToNorm in `normVarList'{c -(}
{txt}  2{com}.         
.         by stateGroup: egen tempMean = mean(`varToNorm')
{txt}  3{com}.         by stateGroup: egen tempSD = sd(`varToNorm')
{txt}  4{com}.         by stateGroup: egen tempNumData = count(`varToNorm')
{txt}  5{com}.         gen tempSE = tempSD/sqrt(tempNumData)
{txt}  6{com}.         
.         gen norm`varToNorm' = (`varToNorm'-tempMean)/tempSD
{txt}  7{com}.         
.         drop tempMean tempSD tempNumData tempSE
{txt}  8{com}.         
.         di "`varToNorm'"
{txt}  9{com}.         
. {c )-}
{txt}(113 missing values generated)
DiffLogReg
(62 missing values generated)
DiffLogHighwayGasUse
(113 missing values generated)
DiffLogRegPerCapita
(62 missing values generated)
DiffLogGasUsePerCapita

{com}. 
. //Generate Colorado Dummy
. gen coDum1 = 0
{txt}
{com}. gen coDum2 = 0
{txt}
{com}. replace coDum1 = 1 if statecode=="CO" & year>=2002 & year<=2009
{txt}(7 real changes made)

{com}. replace coDum2 = 1 if statecode=="CO" & year>=2010
{txt}(9 real changes made)

{com}. 
. drop if coDum1 == 1
{txt}(7 observations deleted)

{com}. 
. 
. //Generate dummy variable for data footnotes
. gen transactionDataDummy = 0
{txt}
{com}. 
. replace transactionDataDummy = 1 if statecode=="AR" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 2 if statecode=="GA" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 3 if statecode=="IA" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 4 if statecode=="IL" & year>=2012
{txt}(7 real changes made)

{com}. replace transactionDataDummy = 5 if statecode=="KY" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 6 if statecode=="LA" & year>=2012
{txt}(7 real changes made)

{com}. replace transactionDataDummy = 7 if statecode=="ME" & year>=2011 //Maine is a state with what looks to not have a consistent change
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 8 if statecode=="ME" & year>2014
{txt}(4 real changes made)

{com}. replace transactionDataDummy = 9 if statecode=="MI" & year>=2011 //Michigan is a state with what looks to not have a consistent change
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 10 if statecode=="MI" & year>2012
{txt}(6 real changes made)

{com}. replace transactionDataDummy = 11 if statecode=="MN" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 12 if statecode=="NV" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 13 if statecode=="OK" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 14 if statecode=="SD" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 15 if statecode=="TN" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 16 if statecode=="TX" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 17 if statecode=="WA" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 18 if statecode=="WI" & year>=2011
{txt}(8 real changes made)

{com}. replace transactionDataDummy = 19 if statecode=="WY" & year>=2011
{txt}(8 real changes made)

{com}. 
. 
. 
. 
. //Local Data Source Controls
. 
. sort state year
{txt}
{com}. 
. python
{txt}{hline 47} python (type {cmd:end} to exit) {hline}
{com}>>> 
>>> import numpy as np
>>> import pandas as p 
>>> from sfi import Data 
>>> 
>>> 
>>> def getDSCDummies(data, col, cutoff):
... 
...         tempExtState = None
... 
...         tempIndex = 0
...         stateCol = 0
... 
...         rows, cols = data.shape
... 
...         dummyExt = []
... 
...         for i in range(rows):
...                 tempDiff = float(data[i,col])
...                 tempState = data[i,stateCol]
... 
... 
...                 if(abs(tempDiff)>cutoff):
...                         tempExtState = tempState
...                         tempIndex+=1
... 
...                 if tempState==tempExtState:
...                         dummyExt.append(tempIndex)
...                 else:
...                         dummyExt.append(0)
... 
... 
...         dummyExt = np.array(dummyExt).reshape((-1,1))
...         return dummyExt
... 
>>> dataCols = ['state', 'year', 'normDiffLogReg', 'normDiffLogHighwayGasUse', 'normDiffLogRegPerCapita', 'normDiffLogGasUsePerCapita']
>>> 
>>> data = np.array(Data.get(dataCols, missingval=np.nan))
>>> 
>>> 
>>> regCutoffLow = 2.93 #Spec. 4
>>> regCutoffPrimary = 4.02 #Spec. 3
>>> regCutoffHigh = 7 #Spec. 2
>>> 
>>> gasUseCutoffLow = 2.93 #Spec. 4
>>> gasUseCutoffPrimary = 4.02 #Spec. 3
>>> gasUseCutoffHigh = 7 #Spec. 2
>>> 
>>> regCol = dataCols.index('normDiffLogReg')
>>> gasUseCol = dataCols.index('normDiffLogHighwayGasUse')
>>> regPerCapitaCol = dataCols.index('normDiffLogRegPerCapita')
>>> gasUsePerCapitaCol = dataCols.index('normDiffLogGasUsePerCapita')
>>> 
>>> rows, cols = data.shape
>>> 
>>> regDummyExtLow = getDSCDummies(data, regCol, regCutoffLow)
>>> regDummyExtPrimary = getDSCDummies(data, regCol, regCutoffPrimary)
>>> regDummyExtHigh = getDSCDummies(data, regCol, regCutoffHigh)
>>> 
>>> gasUseDummyExtLow = getDSCDummies(data, gasUseCol, gasUseCutoffLow)
>>> gasUseDummyExtPrimary = getDSCDummies(data, gasUseCol, gasUseCutoffPrimary)
>>> gasUseDummyExtHigh = getDSCDummies(data, gasUseCol, gasUseCutoffHigh)
>>> 
>>> regPerCapitaDummyExtLow = getDSCDummies(data, regPerCapitaCol, regCutoffLow)
>>> regPerCapitaDummyExtPrimary = getDSCDummies(data, regPerCapitaCol, regCutoffPrimary)
>>> regPerCapitaDummyExtHigh = getDSCDummies(data, regPerCapitaCol, regCutoffHigh)
>>> 
>>> gasUsePerCapitaDummyExtLow = getDSCDummies(data, gasUsePerCapitaCol, gasUseCutoffLow)
>>> gasUsePerCapitaDummyExtPrimary = getDSCDummies(data, gasUsePerCapitaCol, gasUseCutoffPrimary)
>>> gasUsePerCapitaDummyExtHigh = getDSCDummies(data, gasUsePerCapitaCol, gasUseCutoffHigh)
>>> 
>>> Data.addVarInt('regDummyExtSpec4')
>>> Data.store("regDummyExtSpec4",None, regDummyExtLow[:])
>>> Data.addVarInt('regDummyExtSpec3')
>>> Data.store("regDummyExtSpec3",None, regDummyExtPrimary[:])
>>> Data.addVarInt('regDummyExtSpec2')
>>> Data.store("regDummyExtSpec2",None, regDummyExtHigh[:])
>>> 
>>> Data.addVarInt('gasUseDummyExtSpec4')
>>> Data.store("gasUseDummyExtSpec4",None, gasUseDummyExtLow[:])
>>> Data.addVarInt('gasUseDummyExtSpec3')
>>> Data.store("gasUseDummyExtSpec3",None, gasUseDummyExtPrimary[:])
>>> Data.addVarInt('gasUseDummyExtSpec2')
>>> Data.store("gasUseDummyExtSpec2",None, gasUseDummyExtHigh[:])
>>> 
>>> Data.addVarInt('regPerCapitaDummyExtSpec4')
>>> Data.store("regPerCapitaDummyExtSpec4",None, regPerCapitaDummyExtLow[:])
>>> Data.addVarInt('regPerCapitaDummyExtSpec3')
>>> Data.store("regPerCapitaDummyExtSpec3",None, regPerCapitaDummyExtPrimary[:])
>>> Data.addVarInt('regPerCapitaDummyExtSpec2')
>>> Data.store("regPerCapitaDummyExtSpec2",None, regPerCapitaDummyExtHigh[:])
>>> 
>>> Data.addVarInt('gasPerCapitaDummyExtSpec4')
>>> Data.store("gasPerCapitaDummyExtSpec4",None, gasUsePerCapitaDummyExtLow[:])
>>> Data.addVarInt('gasPerCapitaDummyExtSpec3')
>>> Data.store("gasPerCapitaDummyExtSpec3",None, gasUsePerCapitaDummyExtPrimary[:])
>>> Data.addVarInt('gasPerCapitaDummyExtSpec2')
>>> Data.store("gasPerCapitaDummyExtSpec2",None, gasUsePerCapitaDummyExtHigh[:])
>>> 
>>>         
>>> end
{txt}{hline}

{com}. 
. 
. //Generate normalized year values to reduce differences in magnitude of covariates.
. //Scale year for better numerical performance
. local yearScale = 1 
{txt}
{com}. gen normYear = year/`yearScale'
{txt}
{com}. gen quadYear = (year/1)^2
{txt}
{com}. 
. //Establish treatment interacted with pre-treatment population share in metro areas
. frame copy default MetroShares
{txt}
{com}. frame change MetroShares
{txt}
{com}. keep if year==1970
{txt}(2,429 observations deleted)

{com}. 
. cap gen preTreatMetroShare = metropopulation/(metropopulation+nonmetropopulation)
{txt}
{com}. 
. frame change default 
{txt}
{com}. 
. cap frlink m:1 state, frame(MetroShares)
{txt}
{com}. cap frget preTreatMetroShare, from(MetroShares)
{txt}
{com}. 
. cap gen metroIntTreatment = nosafetyind*preTreatMetroShare
{txt}
{com}. 
. frame drop MetroShares
{txt}
{com}. 
{txt}end of do-file

{com}. do GasUseIVEmissions
{txt}
{com}. eststo clear
{txt}
{com}. 
. if("`c(os)'"=="Windows"){c -(}
.         local tableSaveDir = "ReviewResponseResults\"
.         local plotSaveDir = "ReviewResponseResults\"
.         local pythonSaveDir = "PythonScripts\"
. {c )-}
{txt}
{com}. else{c -(}
.         local tableSaveDir = "ReviewResponseResults/"
.         local plotSaveDir = "ReviewResponseResults/"
.         local pythonSaveDir = "PythonScripts/"
. {c )-}
{txt}
{com}. 
. //Establish Control Variable Sets
. //Spec1 controls are the same for both registrations and fuel use 
. local spec1Controls = "c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage"
{txt}
{com}. 
. //Other controls are not the same for both registrations and VMT 
. //Registration Controls
. local spec2RegControls = "`spec1Controls' i.transactionDataDummy"
{txt}
{com}. local spec3RegControls = "`spec2RegControls' i.regDummyExtSpec3"
{txt}
{com}. local spec4RegControls = "`spec2RegControls' i.regDummyExtSpec4"
{txt}
{com}. 
. 
. di "`spec3RegControls'"
{res}c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.transactionDataDummy i.regDummyExtSpec3
{txt}
{com}. 
. //Gas use Controls
. local spec2GasUseControls = "`spec1Controls'"
{txt}
{com}. local spec3GasUseControls = "`spec2GasUseControls' i.gasUseDummyExtSpec3"
{txt}
{com}. local spec4GasUseControls = "`spec2GasUseControls' i.gasUseDummyExtSpec4"
{txt}
{com}. 
. //Absorb Vars are always time and state fixed effects
. local absorbVars = "ib51.stateGroup ib1995.year"
{txt}
{com}. 
. //Establish Cluster Variable
. local clusterVar = "stateGroup"
{txt}
{com}. 
. //Establish primary null
. local primaryNull = 11
{txt}
{com}. local altNull = round(9.7, .1)
{txt}
{com}. local altNull2 = 1
{txt}
{com}. local altNull3 = -4.8
{txt}
{com}. local altNull4 = -6.1
{txt}
{com}. 
. frame create emissions
{txt}
{com}. frame change emissions
{txt}
{com}. 
. if("`c(os)'"=="Windows"){c -(}
.         local dataFile = "CleanedData\EmissionsProgramsV2.xlsx"
. {c )-}
{txt}
{com}. else{c -(}
.         local dataFile = "CleanedData/EmissionsProgramsV2.xlsx"
. {c )-}
{txt}
{com}. 
. import excel using "`dataFile'", first sheet("Clean") case(l)
{res}{text}(4 vars, 51 obs)

{com}. 
. frame change default
{txt}
{com}. frlink m:1 state, frame(emissions)
{res}{txt}  (all observations in frame {bf:default} matched)
{res}{txt}
{com}. frget stateemissionsprogram startemission endemission, from(emissions)
{res}{txt}(734 missing values generated)
{res}{txt}(734 missing values generated)
{res}{txt}{p 2 3 2}
(3 variables copied from linked frame)
{p_end}

{com}. 
. gen emissionind = 0
{txt}
{com}. replace emissionind = 1 if year>=startemission & year<=endemission & stateemissionsprogram==1
{txt}(1,092 real changes made)

{com}. 
. frame drop emissions
{txt}
{com}. 
. //non-normalized models
. local treatmentVar = "1.nosafetyind"
{txt}
{com}. 
. local fsVarsSpec2 = "logregistrations i.nosafetyind `spec2RegControls' i.emissionind"
{txt}
{com}. local rfVarsSpec2 = "loghighwaygasuse i.nosafetyind `spec2GasUseControls' i.emissionind"
{txt}
{com}. 
. local fsOut = "logregistrations"
{txt}
{com}. local rfOut = "loghighwaygasuse"
{txt}
{com}. 
. local treatControl = "nosafetyind"
{txt}
{com}. 
. local fsControlsSpec1 = "`spec1Controls' i.emissionind"
{txt}
{com}. local rfControlsSpec1 = "`spec1Controls' i.emissionind"
{txt}
{com}. 
. local modelTitleSpec1 = "Spec1GasUseEmissions"
{txt}
{com}. local nullLowSpec1 = -4
{txt}
{com}. local nullDeltaSpec1 = 0.001
{txt}
{com}. local nullHighSpec1 = 1
{txt}
{com}. 
. runModelFWL `fsOut', `rfOut', `fsControlsSpec1', `rfControlsSpec1', `treatControl', `absorbVars', `clusterVar', `treatmentVar', `modelTitleSpec1', `nullLowSpec1', `nullDeltaSpec1', `nullHighSpec1', `primaryNull', `altNull', `altNull2', `altNull3', `altNull4'
logregistrations
loghighwaygasuse
c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.emissionind
c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.emissionind
nosafetyind
ib51.stateGroup ib1995.year
Working on:Spec1GasUseEmissions

{txt}      Source {c |}       SS           df       MS      Number of obs   ={res}     2,429
{txt}{hline 13}{c +}{hline 34}   F(1, 2428)      = {res}    33.06
{txt}       Model {c |} {res} .083307463         1  .083307463   {txt}Prob > F        ={res}    0.0000
{txt}    Residual {c |} {res} 6.11761338     2,428   .00251961   {txt}R-squared       ={res}    0.0134
{txt}{hline 13}{c +}{hline 34}   Adj R-squared   ={res}    0.0130
{txt}       Total {c |} {res} 6.20092085     2,429   .00255287   {txt}Root MSE        =   {res}  .0502

{txt}{hline 19}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}logregistrations~s{col 20}{c |} Coefficient{col 32}  Std. err.{col 44}      t{col 52}   P>|t|{col 60}     [95% con{col 73}f. interval]
{hline 19}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
fs_nosafetyind_res {c |}{col 20}{res}{space 2} .0533329{col 32}{space 2} .0092751{col 43}{space 1}    5.75{col 52}{space 3}0.000{col 60}{space 4} .0351449{col 73}{space 3} .0715209
{txt}{hline 19}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}
{txt}scalars:
              r(covar) =  {res}-.0000309513218122
           {txt}r(covarLow) =  {res}-.0000309513218122
          {txt}r(covarHigh) =  {res}-.0000309513218122
           {txt}r(deltaVar) =  {res}.000096423943749
              {txt}r(piVar) =  {res}.0002077284376947
   {txt}r(covarUncorrected) =  {res}-.0000283697954072
  {txt}r(deltaVarUncorrect
    ed)                =  {res}.0000883816068701
   {txt}r(piVarUncorrected) =  {res}.0001904026365471
              {txt}r(delta) =  {res}-.0148651739251812
                 {txt}r(pi) =  {res}.053332921149737
       {txt}r(rfCorrection) =  {res}1.090995594713656
       {txt}r(fsCorrection) =  {res}1.090995594713656
                  {txt}r(N) =  {res}2429
             {txt}r(nClust) =  {res}51
                {txt}r(rfK) =  {res}159
                {txt}r(fsK) =  {res}159
{txt}
{com}. 
. local fsControlsSpec2 = "`spec2RegControls' i.emissionind"
{txt}
{com}. local rfControlsSpec2 = "`spec2GasUseControls' i.emissionind"
{txt}
{com}. 
. local modelTitleSpec2 = "Spec2GasUseEmissions"
{txt}
{com}. local nullLowSpec2 = -4
{txt}
{com}. local nullDeltaSpec2 = 0.001
{txt}
{com}. local nullHighSpec2 = 1
{txt}
{com}. 
. runModelFWL `fsOut', `rfOut', `fsControlsSpec2', `rfControlsSpec2', `treatControl', `absorbVars', `clusterVar', `treatmentVar', `modelTitleSpec2', `nullLowSpec2', `nullDeltaSpec2', `nullHighSpec2', `primaryNull', `altNull', `altNull2', `altNull3', `altNull4'
logregistrations
loghighwaygasuse
c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.transactionDataDummy i.emissionind
c.normYear#i.stateGroup c.quadYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage i.emissionind
nosafetyind
ib51.stateGroup ib1995.year
Working on:Spec2GasUseEmissions

{txt}      Source {c |}       SS           df       MS      Number of obs   ={res}     2,429
{txt}{hline 13}{c +}{hline 34}   F(1, 2428)      = {res}    35.22
{txt}       Model {c |} {res} .080349927         1  .080349927   {txt}Prob > F        ={res}    0.0000
{txt}    Residual {c |} {res} 5.53875665     2,428  .002281201   {txt}R-squared       ={res}    0.0143
{txt}{hline 13}{c +}{hline 34}   Adj R-squared   ={res}    0.0139
{txt}       Total {c |} {res} 5.61910658     2,429  .002313342   {txt}Root MSE        =   {res} .04776

{txt}{hline 19}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}logregistrations~s{col 20}{c |} Coefficient{col 32}  Std. err.{col 44}      t{col 52}   P>|t|{col 60}     [95% con{col 73}f. interval]
{hline 19}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
fs_nosafetyind_res {c |}{col 20}{res}{space 2}  .054291{col 32}{space 2} .0091478{col 43}{space 1}    5.93{col 52}{space 3}0.000{col 60}{space 4} .0363527{col 73}{space 3} .0722294
{txt}{hline 19}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}
{txt}scalars:
              r(covar) =  {res}-.0000332510662156
           {txt}r(covarLow) =  {res}-.0000332510662156
          {txt}r(covarHigh) =  {res}-.0000329727533266
           {txt}r(deltaVar) =  {res}.0000972378286585
              {txt}r(piVar) =  {res}.0001956769974189
   {txt}r(covarUncorrected) =  {res}-.0000302226273748
  {txt}r(deltaVarUncorrect
    ed)                =  {res}.0000883816068701
   {txt}r(piVarUncorrected) =  {res}.0001778551382522
              {txt}r(delta) =  {res}-.0148651739251812
                 {txt}r(pi) =  {res}.0542910360724894
       {txt}r(rfCorrection) =  {res}1.090995594713656
       {txt}r(fsCorrection) =  {res}1.100204353620613
                  {txt}r(N) =  {res}2429
             {txt}r(nClust) =  {res}51
                {txt}r(rfK) =  {res}159
                {txt}r(fsK) =  {res}178
{txt}
{com}. // runModel `fsVarsSpec2', `rfVarsSpec2', `clusterVar', `treatmentVar', `modelTitleSpec2', `nullLowSpec2', `nullDeltaSpec2', `nullHighSpec2', `primaryNull', `altNull', `altNull2', `altNull3', `altNull4'
. //
. //
. // // //Combine all of the IV information
. // // python script "`pythonSaveDir'combineIV.py"
. // //
. // // //Output tables
. // // constructTable GasUsePerCapitaiv; Fleet Gas Use Per Capita; Spec1GasUsePerCapita Spec2GasUsePerCapita Spec3GasUsePerCapita Spec4GasUsePerCapita; `primaryNull'; `altNull'; `altNull2'; `altNull3'; `altNull4'
. // // constructTable GasUseiv; Fleet Gas Use; Spec1GasUse Spec2GasUse Spec3GasUse Spec4GasUse; `primaryNull'; `altNull'; `altNull2'; `altNull3'; `altNull4'
. 
{txt}end of do-file

{com}. 
. 
. //End Timer
. qui timer off 1
{txt}
{com}. qui timer list 1
{txt}
{com}. local minToComplete = `r(t1)'/60
{txt}
{com}. if(`r(t1)'<60){c -(}
.         di "Script took `r(t1)' seconds to complete."   
. {c )-}
{txt}
{com}. else{c -(}
.         di "Script took `minToComplete' minutes to complete."   
{res}Script took 1.236283333333333 minutes to complete.
{com}. {c )-}
{txt}
{com}. 
. cd "ReviewResponseResults"
{res}/Users/connorforsythe/Library/CloudStorage/Box-Box/CMU/Marginal Mileage Project/Publication Replication Code/JAERE/PrimaryModel/ReviewResponseResults
{txt}
{com}. 
. translate "ReviewResponse.smcl" "ReviewResponse.pdf", replace
{txt}
{com}. 
. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}/Users/connorforsythe/Library/CloudStorage/Box-Box/CMU/Marginal Mileage Project/Publication Replication Code/JAERE/PrimaryModel/ReviewResponseResults/ReviewResponse.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res} 2 Sep 2025, 21:48:10
{txt}{.-}
{smcl}
{txt}{sf}{ul off}